diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-03-10 19:16:33 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-03-10 19:16:33 +0900 |
| commit | 80a2172715b6dd225a331d8f2cbccc78dcbd1302 (patch) | |
| tree | 83915294feef374ae5a9baaa6754a50d549b386f /src/server/api/stream/channels/queue-stats.ts | |
| parent | Improve redis config (diff) | |
| download | sharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.tar.gz sharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.tar.bz2 sharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.zip | |
Resolve #4462
Diffstat (limited to 'src/server/api/stream/channels/queue-stats.ts')
| -rw-r--r-- | src/server/api/stream/channels/queue-stats.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/server/api/stream/channels/queue-stats.ts b/src/server/api/stream/channels/queue-stats.ts new file mode 100644 index 0000000000..0bda0cfcb9 --- /dev/null +++ b/src/server/api/stream/channels/queue-stats.ts @@ -0,0 +1,41 @@ +import autobind from 'autobind-decorator'; +import Xev from 'xev'; +import Channel from '../channel'; + +const ev = new Xev(); + +export default class extends Channel { + public readonly chName = 'queueStats'; + public static shouldShare = true; + public static requireCredential = false; + + @autobind + public async init(params: any) { + ev.addListener('queueStats', this.onStats); + } + + @autobind + private onStats(stats: any) { + this.send('stats', stats); + } + + @autobind + 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, + length: body.length + }); + break; + } + } + + @autobind + public dispose() { + ev.removeListener('queueStats', this.onStats); + } +} |