Skip to content

Commit

Permalink
fix(queue-view): improve handling of falsy job.id values
Browse files Browse the repository at this point in the history
Fixes #181.
  • Loading branch information
Eli Skeggs committed Aug 5, 2020
1 parent d65dc76 commit 9415643
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/server/views/dashboard/templates/queueJobsByState.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@
<input class="js-bulk-job" name="jobChecked" type="checkbox" />
</div>

<a role="button" data-toggle="collapse" href="#collapse{{hashIdAttr this.id}}">
<a role="button" data-toggle="collapse" href="#collapse{{hashIdAttr this}}">
<h4 class="header-collapse">
<span class="label label-default">{{ this.id }}</span>
<span class="label label-default">{{#if this.id}}{{ this.id }}{{else}}<em>missing id</em>{{/if}}</span>
{{#if this.data.name}}
<span style="margin-left: 8px">{{ this.data.name }}</span>
{{else if this.name}}
<span style="margin-left: 8px">{{ this.name }}</span>
{{/if}}
</h4>
</a>
<div id="collapse{{hashIdAttr this.id}}" class="collapse">
<div id="collapse{{hashIdAttr this}}" class="collapse">
{{~> dashboard/jobDetails this basePath=../basePath displayJobInline=true queueName=../queueName queueHost=../queueHost jobState=../state }}
</div>
</li>
Expand Down
16 changes: 14 additions & 2 deletions src/server/views/helpers/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const replacer = (key, value) => {
}
};

// For jobs that don't have a valid ID, produce a random ID we can use in its place.
const idMapping = new WeakMap();

const helpers = {
json(obj, pretty = false) {
const args = [obj, replacer];
Expand Down Expand Up @@ -44,8 +47,17 @@ const helpers = {
block.push(options.fn(this));
},

hashIdAttr(id) {
return crypto.createHash('sha256').update(id).digest('hex');
hashIdAttr(obj) {
const { id } = obj;
if (typeof id === 'string') {
return crypto.createHash('sha256').update(id).digest('hex');
}
let mapping = idMapping.get(obj);
if (!mapping) {
mapping = crypto.randomBytes(32).toString('hex');
idMapping.set(obj, mapping);
}
return mapping;
},
};

Expand Down

0 comments on commit 9415643

Please sign in to comment.