1- import { initializeDatabase } from './database.js' ;
21import { emailQueue } from './email-queue.js' ;
32import { generalQueue } from './general-queue.js' ;
3+ import { emailQueue as redisEmailQueue } from './redis-queue.js' ;
44import { parseArgs } from 'util' ;
55
66async function push ( ) {
7- console . log ( 'Initializing database...' ) ;
8- await initializeDatabase ( ) ;
7+ console . log ( 'Adding jobs to demonstrate different queue types...' ) ;
8+ console . log ( '- SQLite queue (general tasks)' ) ;
9+ console . log ( '- SQS queue (production email)' ) ;
10+ console . log ( '- Redis queue (high-performance email)' ) ;
11+ console . log ( '' ) ;
912
10- console . log ( 'Adding some test jobs...' ) ;
11- // Add jobs using the new type-safe API
13+ // SQS queue - using new createQueue(queueUrl) API
1214 const emailJobId1 = await emailQueue . addJob ( 'welcome-email' , {
1315 payload : {
1416 to : 'user@example.com' ,
1517 name : 'John Doe'
1618 }
1719 } ) ;
18- console . log ( `Welcome email job added with ID: ${ emailJobId1 } ` ) ;
20+ console . log ( `[SQS] Welcome email job added with ID: ${ emailJobId1 } ` ) ;
1921
20- const emailJobId2 = await emailQueue . addJob ( 'notification' , {
22+ // Redis queue - using new createRedisQueue(url) API
23+ const emailJobId2 = await redisEmailQueue . addJob ( 'notification' , {
2124 payload : {
2225 to : 'admin@example.com' ,
2326 subject : 'Daily Report' ,
2427 body : 'Here is your daily report...'
2528 }
26- // Note: FileQueue doesn't support priority - would cause TypeScript error
27- // For demo purposes, we removed the priority option
2829 } ) ;
29- console . log ( `Priority notification job added with ID: ${ emailJobId2 } ` ) ;
30+ console . log ( `[Redis] Notification job added with ID: ${ emailJobId2 } ` ) ;
3031
32+ // SQLite queue - using new createQueue('db.sqlite') API
3133 const imageJobId = await generalQueue . addJob ( 'process-image' , {
3234 payload : {
3335 url : 'https://example.com/image.jpg' ,
3436 width : 800 ,
3537 height : 600
3638 }
3739 } ) ;
38- console . log ( `Image job added with ID: ${ imageJobId } ` ) ;
40+ console . log ( `[SQLite] Image job added with ID: ${ imageJobId } ` ) ;
3941
4042 await generalQueue . addJob ( 'generate-report' , {
4143 payload : {
@@ -44,6 +46,7 @@ async function push() {
4446 } ,
4547 delay : 2
4648 } ) ;
49+ console . log ( `[SQLite] Report job added with 2s delay` ) ;
4750}
4851
4952async function run ( ) {
0 commit comments