Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {literal} from 'sequelize';
import Debug from 'debug';
const debug = Debug('backstroke:webhook:consumer');
import RedisMQ from 'rsmq';
const redis = require('redis').createClient(process.env.REDIS_URL);
const redisQueue = new RedisMQ({
client: redis,
ns: 'rsmq',
});
const OK = 'OK', RUNNING = 'RUNNING', ERROR = 'ERROR';
const ONE_HOUR_IN_SECONDS = 60 * 60;
// Logging function to use in webhooks.
function logger() { console.log.apply(console, [' *', ...arguments]); }
// The batch processing function. Eats off the queue and publishes results to redis.
export async function processBatch(WebhookQueue, WebhookStatusStore) {
while (true) {
// Fetch a new webhook event.
const webhook = await WebhookQueue.pop();
// The queue is empty? Cool, we're done.
import repl from 'repl';
import debug from 'debug';
import uuid from 'uuid';
import fetch from 'node-fetch';
import Redis from 'redis';
const redis = Redis.createClient(process.env.REDIS_URL);
import RedisMQ from 'rsmq';
const redisQueue = new RedisMQ({
client: redis,
ns: 'rsmq',
});
const ONE_HOUR_IN_SECONDS = 60 * 60;
const LINK_OPERATION_EXPIRY_TIME_IN_SECONDS = 24 * ONE_HOUR_IN_SECONDS;
export const WebhookStatusStore = {
set(webhookId, status, expiresIn=LINK_OPERATION_EXPIRY_TIME_IN_SECONDS) {
return new Promise((resolve, reject) => {
redis.set(`webhook:status:${webhookId}`, JSON.stringify(status), 'EX', expiresIn, (err, id) => {
if (err) {
reject(err);
} else {
// Resolves the message id.
resolve(id);
}