-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpush-all-product-to-queue.js
34 lines (28 loc) · 1.06 KB
/
push-all-product-to-queue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env node
require('dotenv').config();
const db = require('./libraries/database');
const redisClient = require('./libraries/redis-client');
const RedisQueue = require('hkulekci-simple-redis-queue');
const push_queue = new RedisQueue(redisClient.getClient());
const getAllProductIds = (callback) => {
let sql = "SELECT p.id FROM products p";
db.getConnection(function(err, connection) {
if(err) { console.log(err); callback(true); return; }
// make the query
connection.query(sql, {}, function(err, results) {
connection.release();
if(err) { console.log(err); callback(true); return; }
callback(false, results);
});
});
}
console.log(getAllProductIds((err, response) => {
if (!err) {
for (const index in response) {
const product = response[index]
push_queue.push('product_updates', {'action':'insert', 'productId': product.id}, ((err, res) => {
console.log('Product sent to queue : ' + product.id)
}));
}
}
}))