Skip to content

Instantly share code, notes, and snippets.

@harlesbayu
Created March 30, 2020 12:05
Show Gist options
  • Save harlesbayu/1a99b60ee5af149ebee8d8f12a1916b4 to your computer and use it in GitHub Desktop.
Save harlesbayu/1a99b60ee5af149ebee8d8f12a1916b4 to your computer and use it in GitHub Desktop.
Function rsmq worker
/* eslint-disable no-console */
const RSMQWorker = require('rsmq-worker');
const RedisSMQ = require('rsmq');
const { uploadMultipartVideo } = require('../libs/multipart_upload');
const config = require('../../config');
const rsmq = new RedisSMQ({
url: config.get('REDIS_URL'),
ns: 'rsmq'
});
const worker = new RSMQWorker(config.get('WORKER_TOPIC'), {
rsmq,
maxReceiveCount: 100, // only receive a message 2 times until delete
autostart: true, // start worker on init
});
const listenWorker = () => {
worker.on('message', async (msg, next, msgid) => {
const message = JSON.parse(msg);
const data = {
msgid,
message
};
uploadMultipartVideo({
// data yang dibutuhkan
});
worker.del(data.msgid);
});
worker.start();
};
module.exports = {
listenWorker
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment