Skip to content

Commit

Permalink
feat(parent-children): implement perma-link for bullmq
Browse files Browse the repository at this point in the history
  • Loading branch information
valvfr committed Jun 9, 2021
1 parent 61d93e2 commit bbd2317
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 37 deletions.
2 changes: 1 addition & 1 deletion example/bullmq_with_flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function main() {
name: parentQueueName,

// User-readable display name for the host. Required.
hostId: 'Queue Server 2',
hostId: 'Queue Server 1',

// Queue type (Bull or Bullmq or Bee - default Bull).
type: 'bullmq',
Expand Down
6 changes: 0 additions & 6 deletions public/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ $(document).ready(() => {
}
});

// Set up individual "click on job link" handler
$('.js-job-link').on('click', function (e) {
e.preventDefault();
console.log('job clicked');
});

// Set up individual "remove job" handler
$('.js-remove-job').on('click', function (e) {
e.preventDefault();
Expand Down
26 changes: 17 additions & 9 deletions src/server/views/dashboard/jobDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ async function handler(req, res) {
hasFlows: Flows.hasFlows(),
});

job.parentJobId = JobHelpers.getJobId(job.parentKey);
const {processed, unprocessed} = await job.getDependencies();
if (unprocessed) {
job.children = unprocessed.map((child) => JobHelpers.getJobId(child));
}
_.forOwn(processed, function (value, key) {
job.children.push(JobHelpers.getJobId(key));
});

if (json === 'true') {
// Omit these private and non-stringifyable properties to avoid circular
// references parsing errors.
Expand All @@ -51,6 +42,23 @@ async function handler(req, res) {
job.logs = logs.logs || 'No Logs';
}

if (queue.IS_BULLMQ) {
job.parent = JobHelpers.getKeyProperties(job.parentKey);
const {processed, unprocessed} = await job.getDependencies();
if (unprocessed && unprocessed.length) {
job.unprocessedChildren = unprocessed.map((child) => {
return JobHelpers.getKeyProperties(child);
});
}

if (processed) {
const childrenKeys = Object.keys(processed);
job.processedChildren = childrenKeys.map((child) => {
return JobHelpers.getKeyProperties(child);
});
}
}

return res.render('dashboard/templates/jobDetails', {
basePath,
queueName,
Expand Down
9 changes: 1 addition & 8 deletions src/server/views/dashboard/queueJobsByState.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,7 @@ async function _html(req, res) {
job.showRetryButton = !queue.IS_BEE || jobState === 'failed';
job.retryButtonText = jobState === 'failed' ? 'Retry' : 'Trigger';
job.showPromoteButton = !queue.IS_BEE && jobState === 'delayed';
job.parentJobId = JobHelpers.getJobId(job.parentKey);
const {processed, unprocessed} = await job.getDependencies();
if (unprocessed) {
job.children = unprocessed.map((child) => JobHelpers.getJobId(child));
}
_.forOwn(processed, function (value, key) {
job.children.push(JobHelpers.getJobId(key));
});
job.parent = JobHelpers.getKeyProperties(job.parentKey);
}

let pages = _.range(page - 6, page + 7).filter((page) => page >= 1);
Expand Down
9 changes: 7 additions & 2 deletions src/server/views/helpers/jobHelpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const Helpers = {
getJobId: function (jobData) {
getKeyProperties: function (jobData) {
if (!jobData) return '';
return jobData.substring(jobData.lastIndexOf(':') + 1, jobData.length);
const [, queueName, id] = jobData.split(':');

return {
id,
queueName,
};
},
};

Expand Down
37 changes: 26 additions & 11 deletions src/server/views/partials/dashboard/jobDetails.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,47 @@
<h5>Data</h5>
<pre><code class="json">{{json this.data true}}</code></pre>

{{#if this.queue.IS_BULLMQ}}
{{#if this.parent }}
<div class="row">
<div class="col-sm-12">
<h5>Parent</h5>
<a href="">
<span class="label label-default js-job-link">{{#if this.parentJobId}}{{ this.parentJobId }}{{else}}<em>No parent
job</em>{{/if}}</span>
<a href="{{ basePath }}/{{ encodeURI queueHost }}/{{ encodeURI this.parent.queueName }}/{{ this.parent.id }}">
<span class="label label-default">{{ this.parent.id }}</span>
</a>
</div>
</div>
{{/if}}

{{#if this.unprocessedChildren }}
<div class="row">
<div class="col-sm-12">
<h5>Children</h5>
<h5>Unprocessed Children</h5>

{{#if this.children}}
{{#each this.children}}
<a href="">
<span class="label label-default js-job-link">{{ this }}</span>
{{#each this.unprocessedChildren}}
<a href="{{ ../basePath }}/{{ encodeURI ../queueHost }}/{{ encodeURI this.queueName }}/{{ this.id }}">
<span class="label label-danger">{{ this.id }}</span>
</a>
{{/each}}
{{else}}
<span class="label label-default"><em>No children jobs</em></span>
{{/if}}
</div>
</div>
{{/if}}

{{#if this.processedChildren }}
<div class="row">
<div class="col-sm-12">
<h5>Processed Children</h5>

{{#each this.processedChildren}}
<a href="{{ ../basePath }}/{{ encodeURI ../queueHost }}/{{ encodeURI this.queueName }}/{{ this.id }}">
<span class="label label-success">{{ this.id }}</span>
</a>
{{/each}}
</div>
</div>
{{/if}}
<br>
{{/if}}

{{#if this.logs}}
<h5>Logs</h5>
Expand Down

0 comments on commit bbd2317

Please sign in to comment.