-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for adding tasks in bulk
- Loading branch information
Showing
6 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { Consumer } = require('orkid'); | ||
|
||
async function worker(data, metadata) { | ||
console.log(`Processing task from Queue: ${metadata.qname}. Task ID: ${metadata.id}. Data:`, data); | ||
const result = Math.random(); | ||
console.log(`Task ${metadata.id} done!`); | ||
return result; | ||
} | ||
|
||
const consumer = new Consumer('bulk-add-example-queue', worker, { consumerOptions: { concurrencyPerInstance: 50 } }); | ||
consumer.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "orkid-example", | ||
"version": "1.0.0", | ||
"keywords": [], | ||
"private": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"orkid": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { Producer } = require('orkid'); | ||
|
||
const producer = new Producer('bulk-add-example-queue'); | ||
|
||
async function addTasks() { | ||
// Each task in the array is a object with a mandatory data property | ||
// [{ data: 0}, { data: 1}, { data: 2}, ... { data: 999}] | ||
// | ||
// For de-duplication, you can optionally set dedupKey property too, like: | ||
// [{ data: 0, dedupKey: "unique"}, { data: 1, dedupKey: "unique"}...] | ||
const tasks = Array.from({ length: 1000 }).map((_, i) => ({ data: i })); | ||
|
||
await producer.bulkAddTasks(tasks); | ||
} | ||
|
||
addTasks() | ||
.then(() => { | ||
console.log('Done'); | ||
process.exit(); | ||
}) | ||
.catch(e => console.error(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters