2525│ ├── adapter-drizzle/ # Drizzle ORM adapter (PostgreSQL)
2626│ └── adapter-prisma/ # Prisma ORM adapter (PostgreSQL)
2727├── examples/ # Standalone usage examples
28- │ ├── drizzle-pg/ # Drizzle + node-postgres
29- │ ├── drizzle-postgres/ # Drizzle + postgres.js
30- │ ├── progress-tracking/ # Real-time progress updates
31- │ ├── event-system/ # Comprehensive event monitoring
32- │ └── pm2-workers/ # Production deployment with PM2
3328└── tooling/ # Shared development tools
3429```
3530
@@ -84,21 +79,22 @@ const queue = new Queue(new PostgresPrismaQueueAdapter(prisma), { name: "my-queu
8479// Register job handlers
8580queue .register <EmailPayload , EmailResult >(" send-email" , async (job ) => {
8681 console .log (` Sending email to ${job .payload .to } ` )
87-
82+
8883 // Send email logic here
8984 await sendEmail (job .payload )
90-
91- return {
92- messageId: " msg_123" ,
93- sent: true
85+
86+ // Return result - will be stored in job.result field
87+ return {
88+ messageId: " msg_123" ,
89+ sent: true ,
9490 }
9591})
9692
9793// Add jobs
98- await queue .add (" send-email" , {
99- 100- subject: " Welcome!" ,
101- body: " Welcome to our service!"
94+ await queue .add (" send-email" , {
95+ 96+ subject: " Welcome!" ,
97+ body: " Welcome to our service!" ,
10298})
10399await queue .add (
104100 " send-email" ,
@@ -115,14 +111,7 @@ queue.start()
115111
116112## Examples
117113
118- Check out the [ examples directory] ( ./examples/ ) for complete, runnable examples:
119-
120- - ** [ drizzle-pg] ( ./examples/drizzle-pg/ ) ** - Basic example using Drizzle ORM with node-postgres (pg)
121- - ** [ drizzle-pglite] ( ./examples/drizzle-pglite/ ) ** - Zero-setup example using Drizzle ORM with PGlite (embedded PostgreSQL)
122- - ** [ drizzle-postgres] ( ./examples/drizzle-postgres/ ) ** - Advanced example using Drizzle ORM with postgres.js and recurring jobs
123- - ** [ event-system] ( ./examples/event-system/ ) ** - Comprehensive event monitoring and statistics using Drizzle ORM with postgres.js
124- - ** [ pm2-workers] ( ./examples/pm2-workers/ ) ** - Manage multiple Vorsteh Queues with PM2 using Drizzle ORM with postgres.js
125- - ** [ progress-tracking] ( ./examples/progress-tracking/ ) ** - Real-time job progress tracking using Drizzle ORM with postgres.js
114+ Check out the [ examples directory] ( ./examples/ ) for complete, runnable examples.
126115
127116> ** Note** : All examples demonstrate the UTC-first timezone approach and automatic job cleanup features.
128117
@@ -196,6 +185,49 @@ await queue.add("business-task", payload, {
1961854 . ** Simple and predictable** - no runtime timezone complexity
1971865 . ** Server timezone independent** - works consistently across environments
198187
188+ ## Job Results
189+
190+ Job handlers can return results that are automatically stored and made available:
191+
192+ ``` typescript
193+ interface ProcessResult {
194+ processed: number
195+ errors: string []
196+ duration: number
197+ }
198+
199+ queue .register <{ items: string [] }, ProcessResult >(" process-data" , async (job ) => {
200+ const startTime = Date .now ()
201+ const errors: string [] = []
202+ let processed = 0
203+
204+ for (const item of job .payload .items ) {
205+ try {
206+ await processItem (item )
207+ processed ++
208+ } catch (error ) {
209+ errors .push (` Failed to process ${item }: ${error .message } ` )
210+ }
211+ }
212+
213+ // Return result - automatically stored in job.result field
214+ return {
215+ processed ,
216+ errors ,
217+ duration: Date .now () - startTime ,
218+ }
219+ })
220+
221+ // Access results in events
222+ queue .on (" job:completed" , (job ) => {
223+ const result = job .result as ProcessResult
224+ console .log (` Processed ${result .processed } items in ${result .duration }ms ` )
225+ if (result .errors .length > 0 ) {
226+ console .warn (` Errors: ${result .errors .join (" , " )} ` )
227+ }
228+ })
229+ ```
230+
199231## Progress Tracking
200232
201233``` typescript
@@ -235,6 +267,7 @@ queue.on("job:processing", (job) => {
235267
236268queue .on (" job:completed" , (job ) => {
237269 console .log (` 🎉 Job ${job .name } completed successfully ` )
270+ console .log (` 📊 Result: ` , job .result ) // Access job result
238271})
239272
240273queue .on (" job:failed" , (job ) => {
0 commit comments