-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
89 lines (77 loc) · 1.74 KB
/
tests.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
global.HOOK_NAME = 'job';
const Redibox = require('redibox').default;
const UserHook = require('./src/hook');
const config = {
hooks: {},
log: {
level: 'debug',
},
pubsub: {
eventPrefix: 'myEvents',
subscriber: true,
publisher: true,
},
job: {
queues: [
{
name: 'test2',
concurrency: 5,
throttle: {
limit: 250,
seconds: 10,
},
},
{ name: 'test', concurrency: 10 },
],
},
};
config.hooks[global.HOOK_NAME] = UserHook;
global.firstJob = function (job) {
console.log('Running firstJob')
if (job.data === 3) {
return Promise.reject();
}
return Promise.resolve();
};
global.secondJob = function () {
console.log('Running secondJob')
return Promise.resolve(false);
};
global.thirdJob = function () {
console.log('Running thirdJob')
return Promise.resolve();
};
global.RediBox = new Redibox(config, () => {
global.Hook = RediBox.hooks[global.HOOK_NAME];
RediBox.client.flushall().then(() => {
console.log('HOOK READY');
for (var i = 0; i < 1000; i++) {
Hook.create('test', {
runs: 'firstJob',
data: i,
});
}
// Hook
// .create('test', {
// // runs: ['firstJob', { runs: 'secondJob', queue: 'test2' }, 'thirdJob'],
// // runs: ['firstJob', 'secondJob', 'thirdJob'],
// runs: 'firstJob',
// retries: 1,
// data: {
// foo: 'bar',
// },
// })
// .onRetry(e => {
// retry = true;
// console.log('retry')
// console.log(e)
// console.log('retry')
// })
// .onFailure((e) => {
// console.log(e)
// })
// .onSuccess(e => {
// console.log(e)
// });
});
});