bull通过eclient订阅队列的channel事件消息,然后在当前队列上发出本地或者全局的对应事件
local事件格式为 completed / failed ,代表事件所属job属于本地的queue
global事件格式为 global:completed / global:failed , 代表全局事件,无论 job 是否在本地queue运行
继承
就像多多数nodejs库一样,bull的Queue类继承了EventEmitter
util.inherits(Queue, EventEmitter);
可以直接使用 queue 对象来监听各种事件
on(event: string, callback: (...args: any[]) => void): this;
on(event: 'error', callback: ErrorEventCallback): this;
on(event: 'waiting', callback: WaitingEventCallback): this;
on(event: 'active', callback: ActiveEventCallback<T>): this;
on(event: 'stalled', callback: StalledEventCallback<T>): this;
on(event: 'progress', callback: ProgressEv
本文介绍了Bull任务队列如何通过eclient订阅和发布事件,详细阐述了local(已完成/失败)和global(全局已完成/全局失败)事件的区分。Bull队列继承了EventEmitter,提供了on和once方法监听事件。队列订阅使用psubscribe和subscribe订阅不同类型的channel,并在接收到消息时触发相应的EventEmitter事件,如active、waiting、stalled。对于delayed事件,任务会被推入等待队列;而completed和failed的local事件则直接在本地代码中触发。
订阅专栏 解锁全文
136

被折叠的 条评论
为什么被折叠?



