Sam*_*Sam 7 node.js typescript
我正在尝试将 Bull 实现到我的 TypeScript 项目中。我有以下代码:
索引.ts
import Bull, {
Queue
} from 'bull';
void(async function() {
const monitorQueue: Bull.Queue < any > = new Bull(`stock`, {
redis: {
port: 1234,
host: 'xxxxx',
password: 'xxxxx'
}
});
monitorQueue.on('error', err => {
console.error(err);
});
monitorQueue.on('failed', async function(job, error) {
console.log(error);
});
monitorQueue.on('completed', async function(job, error) {
console.log(error);
});
Promise.all([
monitorQueue.add({
foo: 'bar1'
}),
monitorQueue.add({
foo: 'bar2'
}),
monitorQueue.add({
foo: 'bar3'
}),
monitorQueue.add({
foo: 'bar4'
})
]).then(() => {
monitorQueue.process(4, 'C:/Users/Documents/src/processor.js');
})
})();
Run Code Online (Sandbox Code Playgroud)
处理器.js
module.exports = function(/*job*/) {
return 42;
};
Run Code Online (Sandbox Code Playgroud)
I can see from the console that the new node threads have spawned, but the processor is never run and eventually times out and monitorQueue.on('error')
is called with the following error: Error: job stalled more than allowable limit
.
Console logs:
Debugger listening on ws://127.0.0.1:65243/a4d6d909-6ee8-460c-ad20-4be41e364f17
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
(node:3572) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Debugger listening on ws://127.0.0.1:65249/f0e20585-d0a9-4c07-a24e-c1d05d8ce48c
For help, see: https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:65250/7a49432d-b39c-43c5-949a-5862ee20255d
For help, see: https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:65251/ea8ba70f-823e-4130-9622-0a75b51e8ad9
For help, see: https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:65252/3ce00295-f418-46d8-9c9b-68af69a8a027
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger attached.
Debugger attached.
Debugger attached.
(node:3340) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13784) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19064) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3684) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Error: job stalled more than allowable limit
at C:\Users\Documents\node_modules\bull\lib\queue.js:963:13
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 0)
Run Code Online (Sandbox Code Playgroud)
我已经在一个普通的 JS 项目中测试了这段代码,它工作正常(控制台42
按预期输出)。
归档时间: |
|
查看次数: |
3474 次 |
最近记录: |