How to use rsmq - 2 common examples

To help you get started, we’ve selected a few rsmq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github backstrokeapp / server / src / jobs / webhook-consumer / index.js View on Github external
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.
github backstrokeapp / server / src / models.js View on Github external
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);
        }

rsmq

A really simple message queue based on Redis

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular rsmq functions