Skip to content

Commit 2d199fc

Browse files
author
Brad Vogel
authored
Merge pull request #341 from roggervalf/fix-performance-job-details
Fix performance in job details
2 parents ca4fefc + b4b6a7d commit 2d199fc

5 files changed

Lines changed: 38 additions & 22 deletions

File tree

example/bull.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async function main() {
3030
});
3131

3232
// adding delayed jobs
33-
await queue.add({}, { delay: Date.now() + 60 * 1000 });
33+
const delayedJob = await queue.add({}, { delay: Date.now() + 60 * 1000 });
34+
delayedJob.log('Log message');
3435

3536
Arena(
3637
{

src/server/views/dashboard/jobDetails.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ async function handler(req, res) {
3030
job.retryButtonText = jobState === 'failed' ? 'Retry' : 'Trigger';
3131
const stacktraces = queue.IS_BEE ? job.options.stacktraces : job.stacktrace;
3232

33+
if (!queue.IS_BEE) {
34+
const logs = await queue.getJobLogs(job.id);
35+
job.logs = logs.logs || 'No Logs';
36+
}
37+
3338
return res.render('dashboard/templates/jobDetails', {
3439
basePath,
3540
queueName,

src/server/views/dashboard/queueJobsByState.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ async function _html(req, res) {
103103
} else {
104104
const stateTypes = state === 'waiting' ? ['wait', 'paused'] : state;
105105
jobs = await queue.getJobs(stateTypes, startId, endId, order === 'asc');
106-
await Promise.all(
107-
jobs.map(async (job) => {
108-
const logs = await queue.getJobLogs(job.id);
109-
job.logs = logs.logs || 'No Logs';
110-
return job;
111-
})
112-
);
113106
}
114107

115108
for (const job of jobs) {

src/server/views/helpers/handlebars.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ const replacer = (key, value) => {
1818
// For jobs that don't have a valid ID, produce a random ID we can use in its place.
1919
const idMapping = new WeakMap();
2020

21+
const getTimestamp = (job) => {
22+
// Bull
23+
if (job.timestamp) {
24+
return job.timestamp;
25+
}
26+
27+
// Bee
28+
if (job.options && job.options.timestamp) {
29+
return job.options.timestamp;
30+
}
31+
};
32+
2133
const helpers = {
2234
json(obj, pretty = false) {
2335
const args = [obj, replacer];
@@ -61,10 +73,20 @@ const helpers = {
6173
return mapping;
6274
},
6375

64-
getTimestamp(job) {
65-
return job.timestamp ? job.timestamp : job.options.timestamp;
76+
getDelay(job) {
77+
// Bull
78+
if (job.delay) {
79+
return job.delay + getTimestamp(job);
80+
}
81+
82+
// Bee
83+
if (job.options && job.options.delay) {
84+
return job.options.delay + getTimestamp(job);
85+
}
6686
},
6787

88+
getTimestamp,
89+
6890
encodeURI(url) {
6991
if (typeof url !== 'string') {
7092
return '';

src/server/views/partials/dashboard/jobDetails.hbs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
<div class="col-sm-3">
2626
<h5>Timestamp</h5>
27-
{{#if this.options.timestamp}}
28-
{{moment this.options.timestamp "llll"}}
29-
{{else if this.timestamp}}
30-
{{moment this.timestamp "llll"}}
27+
{{#if (getTimestamp this)}}
28+
{{moment (getTimestamp this) "llll"}}
3129
{{/if}}
3230
</div>
3331

@@ -45,15 +43,10 @@
4543
</div>
4644
{{/if}}
4745

48-
{{#if this.delay}}
46+
{{#if (getDelay this)}}
4947
<div class="col-sm-3">
5048
<h5>Executes At</h5>
51-
{{moment (add this.delay (getTimestamp this) ) "llll"}}
52-
</div>
53-
{{else if this.options.delay}}
54-
<div class="col-sm-3">
55-
<h5>Executes At</h5>
56-
{{moment (add this.options.delay (getTimestamp this) ) "llll"}}
49+
{{moment (getDelay this) "llll"}}
5750
</div>
5851
{{/if}}
5952

@@ -114,5 +107,7 @@
114107
<h5>Data</h5>
115108
<pre><code class="json">{{json this.data true}}</code></pre>
116109

110+
{{#if this.logs}}
117111
<h5>Logs</h5>
118-
<pre><code class="json">{{json this.logs true}}</code></pre>
112+
<pre><code class="json">{{json this.logs true}}</code></pre>
113+
{{/if}}

0 commit comments

Comments
 (0)