2022-04-17 08:42:13 +03:00
|
|
|
import Xev from 'xev';
|
2022-02-27 04:07:39 +02:00
|
|
|
import Channel from '../channel.js';
|
2019-03-10 12:16:33 +02:00
|
|
|
|
2022-04-17 08:42:13 +03:00
|
|
|
const ev = new Xev();
|
2019-03-10 12:16:33 +02:00
|
|
|
|
|
|
|
export default class extends Channel {
|
|
|
|
public readonly chName = 'queueStats';
|
|
|
|
public static shouldShare = true;
|
|
|
|
public static requireCredential = false;
|
|
|
|
|
2022-02-27 04:07:39 +02:00
|
|
|
constructor(id: string, connection: Channel['connection']) {
|
|
|
|
super(id, connection);
|
|
|
|
this.onStats = this.onStats.bind(this);
|
|
|
|
this.onMessage = this.onMessage.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-03-10 12:16:33 +02:00
|
|
|
public async init(params: any) {
|
|
|
|
ev.addListener('queueStats', this.onStats);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onStats(stats: any) {
|
|
|
|
this.send('stats', stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
public onMessage(type: string, body: any) {
|
|
|
|
switch (type) {
|
|
|
|
case 'requestLog':
|
|
|
|
ev.once(`queueStatsLog:${body.id}`, statsLog => {
|
|
|
|
this.send('statsLog', statsLog);
|
|
|
|
});
|
|
|
|
ev.emit('requestQueueStatsLog', {
|
|
|
|
id: body.id,
|
2021-12-09 16:58:30 +02:00
|
|
|
length: body.length,
|
2019-03-10 12:16:33 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public dispose() {
|
|
|
|
ev.removeListener('queueStats', this.onStats);
|
|
|
|
}
|
|
|
|
}
|