Skip to content

Commit

Permalink
webhooks: use queue instead of direct http request
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed Apr 30, 2018
1 parent 5f0ef2d commit c87e592
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions website/server/libs/webhook.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import got from 'got';
import { isURL } from 'validator';
import logger from './logger';
import nconf from 'nconf';
import { v4 as uuid } from 'uuid';
import Queue from '../../libs/queue';

const IS_PRODUCTION = nconf.get('IS_PROD');

function sendWebhook (url, body) {
got.post(url, {
body,
json: true,
}).catch(err => logger.error(err));
}

function isValidWebhook (hook) {
return hook.enabled && isURL(hook.url, {
require_tld: IS_PRODUCTION ? true : false, // eslint-disable-line camelcase
Expand Down Expand Up @@ -57,7 +50,7 @@ export class WebhookSender {
this.attachDefaultData(user, body);

hooks.forEach((hook) => {
sendWebhook(hook.url, body);
Queue.sendMessage({url: hook.url, body}, `${hook.id}-${uuid()}`);
});
}
}
Expand Down

0 comments on commit c87e592

Please sign in to comment.