/
types.ts
65 lines (58 loc) · 1.62 KB
/
types.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
import { JobState } from '@vendure/common/lib/generated-types';
import { ID, JsonCompatible } from '@vendure/common/lib/shared-types';
import { RequestContext } from '../api/common/request-context';
import { Job } from './job';
/**
* @description
* Used to configure a new {@link JobQueue} instance.
*
* @docsCategory JobQueue
* @docsPage types
*/
export interface CreateQueueOptions<T extends JobData<T>> {
/**
* @description
* The name of the queue, e.g. "image processing", "re-indexing" etc.
*/
name: string;
/**
* @description
* Defines the work to be done for each job in the queue. The returned promise
* should resolve when the job is complete, or be rejected in case of an error.
*/
process: (job: Job<T>) => Promise<any>;
}
/**
* @description
* A JSON-serializable data type which provides a {@link Job}
* with the data it needs to be processed.
*
* @docsCategory JobQueue
* @docsPage types
*/
export type JobData<T> = JsonCompatible<T>;
/**
* @description
* Used to instantiate a new {@link Job}
*
* @docsCategory JobQueue
* @docsPage types
*/
export interface JobConfig<T extends JobData<T>> {
queueName: string;
data: T;
retries?: number;
attempts?: number;
id?: ID;
state?: JobState;
progress?: number;
result?: any;
error?: any;
createdAt?: Date;
startedAt?: Date;
settledAt?: Date;
}
export type JobOptions<Data extends JsonCompatible<Data>> = Pick<JobConfig<Data>, 'retries'> & {
ctx?: RequestContext
};
export type JobQueueStrategyJobOptions<Data extends JsonCompatible<Data>> = Omit<JobOptions<Data>, "retries">