-
Notifications
You must be signed in to change notification settings - Fork 414
/
minimal-job.ts
137 lines (133 loc) · 2.93 KB
/
minimal-job.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { JobsOptions, JobJsonSandbox } from '../types';
import { JobJson } from './job-json';
import { ParentKeys } from './parent';
export type BulkJobOptions = Omit<JobsOptions, 'repeat'>;
export interface MoveToWaitingChildrenOpts {
child?: {
id: string;
queue: string;
};
}
export interface DependenciesOpts {
processed?: {
cursor?: number;
count?: number;
};
unprocessed?: {
cursor?: number;
count?: number;
};
}
/**
* MinimalJob
*/
export interface MinimalJob<
DataType = any,
ReturnType = any,
NameType extends string = string,
> {
/**
* The name of the Job
*/
name: NameType;
/**
* The payload for this job.
*/
data: DataType;
/**
* The options object for this job.
*/
opts: JobsOptions;
id?: string;
/**
* The progress a job has performed so far.
* @defaultValue 0
*/
progress: number | object;
/**
* The value returned by the processor when processing this job.
* @defaultValue null
*/
returnvalue: ReturnType;
/**
* Stacktrace for the error (for failed jobs).
* @defaultValue null
*/
stacktrace: string[];
/**
* An amount of milliseconds to wait until this job can be processed.
* @defaultValue 0
*/
delay: number;
/**
* Timestamp when the job was created (unless overridden with job options).
*/
timestamp: number;
/**
* Number of attempts after the job has failed.
* @defaultValue 0
*/
attemptsMade: number;
/**
* Reason for failing.
*/
failedReason: string;
/**
* Timestamp for when the job finished (completed or failed).
*/
finishedOn?: number;
/**
* Timestamp for when the job was processed.
*/
processedOn?: number;
/**
* Fully qualified key (including the queue prefix) pointing to the parent of this job.
*/
parentKey?: string;
/**
* Object that contains parentId (id) and parent queueKey.
*/
parent?: ParentKeys;
/**
* Base repeat job key.
*/
repeatJobKey?: string;
/**
* Prepares a job to be serialized for storage in Redis.
* @returns
*/
asJSON(): JobJson;
/**
* Prepares a job to be passed to Sandbox.
* @returns
*/
asJSONSandbox(): JobJsonSandbox;
/**
* Updates a job's data
*
* @param data - the data that will replace the current jobs data.
*/
updateData(data: DataType): Promise<void>;
/**
* Updates a job's progress
*
* @param progress - number or object to be saved as progress.
*/
updateProgress(progress: number | object): Promise<void>;
/**
* Logs one row of log data.
*
* @param logRow - string with log data to be logged.
*/
log(logRow: string): Promise<number>;
get queueName(): string;
/**
* @returns the prefix that is used.
*/
get prefix(): string;
/**
* @returns it includes the prefix, the namespace separator :, and queue name.
* @see https://www.gnu.org/software/gawk/manual/html_node/Qualified-Names.html
*/
get queueQualifiedName(): string;
}