forked from felixmosh/bull-board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
103 lines (85 loc) · 2.7 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// import { Job, JobOptions } from 'bull'
// import { Job as JobMq, JobsOptions } from 'bullmq'
import React from 'react'
import * as Redis from 'ioredis'
import { Status } from '../ui/components/constants'
export type JobCleanStatus =
| 'completed'
| 'wait'
| 'active'
| 'delayed'
| 'failed'
export type JobStatus = Status
export type JobCounts = Record<JobStatus, number>
export interface QueueAdapter<BullJob> {
readonly client: Promise<Redis.Redis>
readonly readOnlyMode: boolean
getName(): string
getJob(id: string): Promise<BullJob | undefined | null>
getJobs(
jobStatuses: JobStatus[],
start?: number,
end?: number,
): Promise<BullJob[]>
getJobCounts(...jobStatuses: JobStatus[]): Promise<JobCounts>
clean(queueStatus: JobCleanStatus, graceTimeMs: number): Promise<any>
}
export interface QueueAdapterOptions {
readOnlyMode: boolean
}
export interface BullBoardQueue<BullJob> {
queue: QueueAdapter<BullJob>
}
export interface BullBoardQueues<BullJob> {
[key: string]: BullBoardQueue<BullJob>
}
export interface ValidMetrics {
total_system_memory: string
redis_version: string
used_memory: string
mem_fragmentation_ratio: string
connected_clients: string
blocked_clients: string
}
export type GenAppJob<JobOpts> = {
id: string | number | undefined
timestamp: number | null
processedOn?: number | null
finishedOn?: number | null
stacktrace: string[] | null
opts: JobOpts
delay: number | undefined
returnValue: string | Record<string | number, any> | null
}
// NOTE: The additional props type probably could be omitted, depending on the actual usage of the props
export type AppJob<JobOpts, AddProps> = AddProps extends Record<string, never>
? GenAppJob<JobOpts>
: GenAppJob<JobOpts> & AddProps
export interface AppQueue<JobOpts, AddProps> {
name: string
counts: Record<Status, number>
jobs: AppJob<JobOpts, AddProps>[]
readOnlyMode: boolean
}
export type SelectedStatuses<JobOpts, AddProps> = Record<
AppQueue<JobOpts, AddProps>['name'],
Status
>
export interface QueueActions<JobOpts, AddProps> {
promoteJob: (
queueName: string,
) => (job: AppJob<JobOpts, AddProps>) => () => Promise<void>
retryJob: (
queueName: string,
) => (job: AppJob<JobOpts, AddProps>) => () => Promise<void>
cleanJob: (
queueName: string,
) => (job: AppJob<JobOpts, AddProps>) => () => Promise<void>
retryAll: (queueName: string) => () => Promise<void>
cleanAllDelayed: (queueName: string) => () => Promise<void>
cleanAllFailed: (queueName: string) => () => Promise<void>
cleanAllCompleted: (queueName: string) => () => Promise<void>
setSelectedStatuses: React.Dispatch<
React.SetStateAction<SelectedStatuses<JobOpts, AddProps>>
>
}