Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/firing-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ A hook can be "fired" in a variety of ways:
In each case, the hooks service creates a task based on the hook definition and
submits it to the Queue service via `Queue.createTask`.

Such tasks always have `taskGroupId` equal to their `taskId`.
If the task definition does not specify a `taskGroupId`, it is set the created
task's `taskId`.

## JSON-e Rendering

Expand All @@ -23,8 +24,8 @@ fired, that template is rendered and the result is submitted to

The context for that rendering is an object with property `firedBy`, giving the
action that led to the hook firing; as well as `taskId` giving the taskId (and
taskGroupId) of the task being created. The other properties of the object vary
depending on the `firedBy` property.
default `taskGroupId`) of the task being created. The other properties of the
object vary depending on the `firedBy` property.

### Scheduled Tasks

Expand Down
10 changes: 7 additions & 3 deletions src/taskcreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ class TaskCreator {
if (!task.expires) {
task.expires = taskcluster.fromNowJSON(hook.expires, created);
}
// set the taskGroupId to the taskId, thereby creating a new task group
// and following the convention for decision tasks.
task.taskGroupId = options.taskId;

// If the template did not set a taskGroupId, then set the taskGroupId to
// the taskId, thereby creating a new task group and following the
// convention for decision tasks.
if (!task.taskGroupId) {
task.taskGroupId = options.taskId;
}
return task;
}

Expand Down
18 changes: 15 additions & 3 deletions test/taskcreator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ suite('taskcreator_test.js', function() {
firedBy: 'schedule',
}, {taskId});
const task = await fetchFiredTask(taskId);
assume(taskId).equals(task.taskGroupId); // the default
assume(task.extra).deeply.equals({
context: {
valueFromContext: 55,
Expand All @@ -144,13 +145,24 @@ suite('taskcreator_test.js', function() {
hook.task.then.created = {$fromNow: '0 seconds'};
hook.task.then.deadline = {$fromNow: '1 minute'};
hook.task.then.expires = {$fromNow: '2 minutes'};
return await helper.Hook.create(hook);
await helper.Hook.create(hook);
let taskId = taskcluster.slugid();
let resp = await creator.fire(hook, {}, {taskId});

const task = await fetchFiredTask(taskId);
assume(new Date(task.deadline) - new Date(task.created)).to.equal(60000);
assume(new Date(task.expires) - new Date(task.created)).to.equal(120000);
});

test('firing a real task that sets its own taskGroupId works', async function() {
let hook = _.cloneDeep(defaultHook);
hook.task.then.taskGroupId = taskcluster.slugid();
await helper.Hook.create(hook);
let taskId = taskcluster.slugid();
let resp = await creator.fire(hook, {}, {taskId});

const task = await fetchFiredTask(taskId);
assume(new Date(task.expires) - new Date(task.created)).to.equal(60000);
assume(new Date(task.deadline) - new Date(task.created)).to.equal(120000);
assume(task.taskGroupId).equals(hook.task.then.taskGroupId);
});

test('firing a real task includes values from context', async function() {
Expand Down