@@ -46,94 +46,6 @@ const queueManager = new QueueManager(adapter);
4646const emailQueue = queueManager .getQueue (' emails' );
4747```
4848
49- ### 3. Painful Serialization Requirements
50-
51- ** Problem** : Users must implement custom serializers for every job type with boilerplate switch statements.
52-
53- ** Current Requirement** :
54- ``` typescript
55- export class JobSerializer implements Serializer {
56- deserialize(payload : Buffer ): any {
57- const data = JSON .parse (payload .toString ());
58- switch (data .constructor ) {
59- case ' EmailJob' : return new EmailJob (data .to , data .subject , data .body );
60- case ' ImageJob' : return new ImageProcessingJob (data .url , data .resize );
61- // ... repeat for every job type
62- }
63- }
64- }
65- ```
66-
67- ** Proposed Solutions** :
68-
69- Option A - Data-based jobs (like Bull/BullMQ):
70- ``` typescript
71- const emailQueue = createQueue <EmailJobData >(' emails' );
72- await emailQueue .add ({ to: ' user@example.com' , subject: ' Hello' });
73-
74- emailQueue .process (async (job ) => {
75- await sendEmail (job .data .to , job .data .subject );
76- });
77- ```
78-
79- Option B - Auto-serialization with decorators:
80- ``` typescript
81- @Serializable (' EmailJob' )
82- export class EmailJob implements Job {
83- constructor (public to : string , public subject : string ) {}
84- }
85- ```
86-
87- Option C - Registry pattern:
88- ``` typescript
89- const registry = new JobRegistry ();
90- registry .register (' EmailJob' , EmailJob );
91- const serializer = new RegistrySerializer (registry );
92- ```
93-
94- ### 4. Missing Job Options API
95-
96- ** Problem** : No way to pass job-specific options like delay, priority, or retry configuration.
97-
98- ** Current** : Jobs are pushed with no options.
99-
100- ** Proposed Solution** :
101- ``` typescript
102- // Options parameter approach
103- await queue .push (job , {
104- delay: 5000 ,
105- priority: 10 ,
106- attempts: 5 ,
107- backoff: { type: ' exponential' , delay: 2000 }
108- });
109- ```
110-
111- ### 5. Overly Complex Job Classes
112-
113- ** Problem** : Requiring class implementations for simple jobs adds unnecessary boilerplate.
114-
115- ** Current** :
116- ``` typescript
117- export class EmailJob implements Job {
118- constructor (private to : string , private subject : string , private body : string ) {}
119- async execute(queue : Queue ): Promise <void > {
120- // send email logic
121- }
122- }
123- ```
124-
125- ** Proposed Solution** : Support both patterns:
126- ``` typescript
127- // Simple function-based jobs
128- emailQueue .process (async (job ) => {
129- const { to, subject, body } = job .data ;
130- await sendEmail (to , subject , body );
131- });
132-
133- // Complex class-based jobs (when needed)
134- emailQueue .process (EmailJobHandler );
135- ```
136-
13749### 6. Poor Worker Management
13850
13951** Problem** :
0 commit comments