2022-04-17 07:42:13 +02:00
|
|
|
import Xev from 'xev';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-12-04 07:03:09 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import Channel from '../channel.js';
|
2019-03-10 11:16:33 +01:00
|
|
|
|
2022-04-17 07:42:13 +02:00
|
|
|
const ev = new Xev();
|
2019-03-10 11:16:33 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
class QueueStatsChannel extends Channel {
|
2019-03-10 11:16:33 +01:00
|
|
|
public readonly chName = 'queueStats';
|
|
|
|
public static shouldShare = true;
|
|
|
|
public static requireCredential = false;
|
|
|
|
|
2022-02-27 03:07:39 +01:00
|
|
|
constructor(id: string, connection: Channel['connection']) {
|
|
|
|
super(id, connection);
|
2022-12-04 07:03:09 +01:00
|
|
|
//this.onStats = this.onStats.bind(this);
|
|
|
|
//this.onMessage = this.onMessage.bind(this);
|
2022-02-27 03:07:39 +01:00
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2019-03-10 11:16:33 +01:00
|
|
|
public async init(params: any) {
|
|
|
|
ev.addListener('queueStats', this.onStats);
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2019-03-10 11:16:33 +01:00
|
|
|
private onStats(stats: any) {
|
|
|
|
this.send('stats', stats);
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2019-03-10 11:16:33 +01:00
|
|
|
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 15:58:30 +01:00
|
|
|
length: body.length,
|
2019-03-10 11:16:33 +01:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2019-03-10 11:16:33 +01:00
|
|
|
public dispose() {
|
|
|
|
ev.removeListener('queueStats', this.onStats);
|
|
|
|
}
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class QueueStatsChannelService {
|
|
|
|
public readonly shouldShare = QueueStatsChannel.shouldShare;
|
|
|
|
public readonly requireCredential = QueueStatsChannel.requireCredential;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
public create(id: string, connection: Channel['connection']): QueueStatsChannel {
|
|
|
|
return new QueueStatsChannel(
|
|
|
|
id,
|
|
|
|
connection,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|