-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
55 lines (38 loc) · 1.24 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express=require('express')
const { addRefundTask } = require("./refundQueue")
const { refundWorker } = require("./worker")
const { addNotificationTask } = require('./notificationQueue')
const { notificationWorker }=require('./worker')
async function init(){
const app=express()
const PORT = 8000;
const order1={
id:"order1",
amount:4000,
user_id:"user1"
}
const order2={
id:"order2",
amount:10000,
user_id:"user2"
}
app.listen(PORT,()=>{
console.log("Server running at port 8000")
})
await addRefundTask(order1);
await addRefundTask(order2)
refundWorker.on('completed', async(job) => {
console.log(`Refund Job ${job.id} has completed!`);
await addNotificationTask(job.data.user_id,job.data.id);
});
refundWorker.on('failed', (job, err) => {
console.log(`Refund Job ${job.id} has failed with ${err.message}`);
});
notificationWorker.on('completed', (job) => {
console.log(`Notification Job ${job.id} has completed!`);
});
notificationWorker.on('failed', (job, err) => {
console.log(`Notification Job ${job.id} has failed with ${err.message}`);
});
}
init()