Skip to content

Commit 9415643

Browse files
author
Eli Skeggs
committed
fix(queue-view): improve handling of falsy job.id values
Fixes #181.
1 parent d65dc76 commit 9415643

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/server/views/dashboard/templates/queueJobsByState.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@
9393
<input class="js-bulk-job" name="jobChecked" type="checkbox" />
9494
</div>
9595

96-
<a role="button" data-toggle="collapse" href="#collapse{{hashIdAttr this.id}}">
96+
<a role="button" data-toggle="collapse" href="#collapse{{hashIdAttr this}}">
9797
<h4 class="header-collapse">
98-
<span class="label label-default">{{ this.id }}</span>
98+
<span class="label label-default">{{#if this.id}}{{ this.id }}{{else}}<em>missing id</em>{{/if}}</span>
9999
{{#if this.data.name}}
100100
<span style="margin-left: 8px">{{ this.data.name }}</span>
101101
{{else if this.name}}
102102
<span style="margin-left: 8px">{{ this.name }}</span>
103103
{{/if}}
104104
</h4>
105105
</a>
106-
<div id="collapse{{hashIdAttr this.id}}" class="collapse">
106+
<div id="collapse{{hashIdAttr this}}" class="collapse">
107107
{{~> dashboard/jobDetails this basePath=../basePath displayJobInline=true queueName=../queueName queueHost=../queueHost jobState=../state }}
108108
</div>
109109
</li>

src/server/views/helpers/handlebars.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const replacer = (key, value) => {
1414
}
1515
};
1616

17+
// For jobs that don't have a valid ID, produce a random ID we can use in its place.
18+
const idMapping = new WeakMap();
19+
1720
const helpers = {
1821
json(obj, pretty = false) {
1922
const args = [obj, replacer];
@@ -44,8 +47,17 @@ const helpers = {
4447
block.push(options.fn(this));
4548
},
4649

47-
hashIdAttr(id) {
48-
return crypto.createHash('sha256').update(id).digest('hex');
50+
hashIdAttr(obj) {
51+
const { id } = obj;
52+
if (typeof id === 'string') {
53+
return crypto.createHash('sha256').update(id).digest('hex');
54+
}
55+
let mapping = idMapping.get(obj);
56+
if (!mapping) {
57+
mapping = crypto.randomBytes(32).toString('hex');
58+
idMapping.set(obj, mapping);
59+
}
60+
return mapping;
4961
},
5062
};
5163

0 commit comments

Comments
 (0)