Created
March 30, 2020 12:05
-
-
Save harlesbayu/1a99b60ee5af149ebee8d8f12a1916b4 to your computer and use it in GitHub Desktop.
Function rsmq worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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