Skip to content

Commit

Permalink
fix(job-details): show progress for bullmq
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Jun 7, 2021
1 parent 7d5b1bf commit 8341174
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion example/bee.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {
});

// Fake process function to move newly created jobs in the UI through a few of the job states.
queue.process(async function () {
queue.process(async function (job) {
// Wait 5sec
await new Promise((res) => setTimeout(res, 5000));

Expand All @@ -36,6 +36,8 @@ async function main() {
.delayUntil(Date.now() + 60 * 1000)
.save();

const job = await queue.createJob({}).save();

Arena(
{
Bee,
Expand Down
5 changes: 4 additions & 1 deletion example/bull.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ async function main() {
});

// Fake process function to move newly created jobs in the UI through a few of the job states.
queue.process(async function () {
queue.process(async function (job) {
// Wait 5sec
job.progress(20);
await new Promise((res) => setTimeout(res, 5000));

// Randomly succeeds or fails the job to put some jobs in completed and some in failed.
Expand All @@ -31,6 +32,8 @@ async function main() {
}
});

await queue.add({});

// adding delayed jobs
const delayedJob = await queue.add({}, {delay: 60 * 1000});
delayedJob.log('Log message');
Expand Down
4 changes: 3 additions & 1 deletion example/bullmq.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ async function main() {

new Worker(
queueName,
async function () {
async function (job) {
await job.updateProgress(20);

// Wait 5sec
await new Promise((res) => setTimeout(res, 5000));

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"bee-queue": "^1.3.1",
"bee-queue": "^1.4.0",
"bull": "^3.22.6",
"bullmq": "^1.28.0",
"express": "^4.17.1",
Expand Down
1 change: 1 addition & 0 deletions src/server/queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Queues {

const {Bull} = this._config;
queue = new Bull(name, options);
queue.IS_BULL = true;
}

this._queues[queueHost] = this._queues[queueHost] || {};
Expand Down
21 changes: 18 additions & 3 deletions src/server/views/partials/dashboard/jobDetails.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
</div>
</div>

{{#unless this.queue.IS_BEE}}
<h5>Progress</h5>
{{#if this.queue.IS_BULL}}
{{#if (isNumber this._progress)}}
<h5>Progress</h5>
<div class="progress">
<div class="progress-bar
{{#eq jobState 'failed'}}
Expand All @@ -90,7 +90,22 @@
{{else}}
<pre>{{json this._progress true}}</pre>
{{/if}}
{{/unless}}
{{else if this.queue.IS_BULLMQ}}
{{#if (isNumber this.progress)}}
<h5>Progress</h5>
<div class="progress">
<div class="progress-bar
{{#eq jobState 'failed'}}
progress-bar-danger
{{/eq}}" role="progressbar" aria-valuenow="{{ this.progress }}" aria-valuemin="0" aria-valuemax="100"
style="width: {{ this.progress }}%; min-width: 2em;">
{{ this.progress }}%
</div>
</div>
{{else}}
<pre>{{json this.progress true}}</pre>
{{/if}}
{{/if}}

{{#if this.returnvalue}}
<h5>Return Value</h5>
Expand Down

0 comments on commit 8341174

Please sign in to comment.