-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (57 loc) · 1.79 KB
/
Copy pathindex.js
File metadata and controls
68 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ApiClient from './lib/ApiClient.js';
// CMS API client
const api = new ApiClient({
baseUrl: process.env.APCMS_API_ROOT,
defaultHeaders: {
Authorization: `Bearer ${process.env.APCMS_API_TOKEN}`
}
});
// Unique ID for this process instance.
// Only one PipelineTask runner can claim a specific task at a time. This
// allows multiple runners to help distribute the load of many new tasks, while
// ensuring only one runner works in a particular task.
const taskRunnerId = crypto.randomUUID();
// "Claim" a task to start
const [ task ] = await api.post('pipelineTasks', 'claim', {
taskRunnerId,
label: 'example'
});
// If no task, there's nothing to do
if (!task) {
console.debug('No tasks.');
process.exit(0);
}
// Start processing the task
try {
console.debug('Starting Task: ', task);
task.Asset.Variants = await api.get('assets', task.Asset.id, 'variants');
console.debug('Asset:', task.Asset);
// ***** TODO TODO TODO *****
//
// This is where you put your custom code for how you want to handle the asset.
// Use the CMS API to manipulate the data. For example, perhaps you wish to
// update the tags of an asset:
//
// task.Asset.tags = {
// ...task.Asset.tags,
// ARTIST: 'EXAMPLE ARTIST',
// TITLE: 'EXAMPLE TITLE'
// };
// await api.put('assets', task.Asset.id, task.Asset);
//
// ***** TODO TODO TODO *****
// Task succeeded. Clear it.
await api.delete('pipelineTasks', task.id);
console.debug('Success.');
} catch(e) {
console.error('Task failed.', e);
// Tell the API that the task failed, so it can be retried later
await api.put('pipelineTasks', task.id, {
...task,
taskRunnerId: null,
status: 'failed',
failCount: task.failCount + 1,
taskRunnerUpdated: new Date()
});
process.exit(1);
}