@nexrender/worker 1.42.3 → 1.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexrender/worker",
3
- "version": "1.42.3",
3
+ "version": "1.43.0",
4
4
  "author": "inlife",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -11,13 +11,13 @@
11
11
  },
12
12
  "pkg": {
13
13
  "targets": [
14
- "node14-macos-x64",
15
- "node14-win-x64"
14
+ "node18-macos-x64",
15
+ "node18-win-x64"
16
16
  ]
17
17
  },
18
18
  "dependencies": {
19
19
  "@nexrender/api": "^1.42.2",
20
- "@nexrender/core": "^1.42.2",
20
+ "@nexrender/core": "^1.43.0",
21
21
  "@nexrender/types": "^1.42.2",
22
22
  "arg": "^4.1.0",
23
23
  "chalk": "^2.4.2",
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "148263d6f733edb7058cfd8e05af8114a1ce71a8"
29
+ "gitHead": "5a13aa8b32ad67c24100311be671224cfdb525a2"
30
30
  }
package/readme.md CHANGED
@@ -81,6 +81,8 @@ Available settings (almost same as for `nexrender-core`):
81
81
  * `addLicense` - boolean, providing false will disable ae_render_only_node.txt license file auto-creation (true by default)
82
82
  * `forceCommandLinePatch` - boolean, providing true will force patch re-installation
83
83
  * `stopOnError` - boolean, stop the pick-up-and-render process if an error occurs (false by default)
84
+ * `exitOnEmptyQueue` - boolean, stop the worker if too many empty queues are detected (false by default)
85
+ * `tolerateEmptyQueues` - number, amount of empty queues to tolerate before exiting (defults to zero).If specified will be used instead of NEXRENDER_TOLERATE_EMPTY_QUEUES env variable
84
86
  * `polling` - number, amount of miliseconds to wait before checking queued projects from the api, if specified will be used instead of NEXRENDER_API_POLLING env variable
85
87
  * `header` - string, Define custom header that the worker will use to communicate with nexrender-server. Accepted format follows curl or wget request header definition, eg. `--header="Some-Custom-Header: myCustomValue"`.
86
88
  * `tagSelector` - string, (optional) provide the string tags (example `primary,plugins,halowell` : comma delimited) to pickup the job with specific tags. Leave it false to ignore and pick a random job from the server with no specific tags. Tags name must be an alphanumeric.
package/src/bin.js CHANGED
@@ -24,7 +24,9 @@ const args = arg({
24
24
  '--cache-path': String,
25
25
 
26
26
  '--stop-on-error': Boolean,
27
-
27
+ '--exit-on-empty-queue': Boolean,
28
+ '--tolerate-empty-queues': Number,
29
+
28
30
  '--skip-cleanup': Boolean,
29
31
  '--skip-render': Boolean,
30
32
  '--no-license': Boolean,
@@ -108,6 +110,13 @@ if (args['--help']) {
108
110
  --stop-on-error forces worker to stop if processing/rendering error occures,
109
111
  otherwise worker will report an error, and continue working
110
112
 
113
+ --exit-on-empty-queue worker will exit when too many empty queues (see --tolerate-empty-queues) have been detected.
114
+ Useful when running on AWS EC2, to allow the instance to self-terminate and reduce compute costs
115
+
116
+ --tolerate-empty-queues worker will check an empty queue this many times before exiting (if that option has
117
+ been set using --exit-on-empty-queues). Defaults to zero. If specified will be used instead of
118
+ NEXRENDER_TOLERATE_EMPTY_QUEUES env variable
119
+
111
120
  --no-license prevents creation of the ae_render_only_node.txt file (enabled by default),
112
121
  which allows free usage of trial version of Adobe After Effects
113
122
 
@@ -200,6 +209,8 @@ opt('debug', '--debug');
200
209
  opt('multiFrames', '--multi-frames');
201
210
  opt('reuse', '--reuse');
202
211
  opt('stopOnError', '--stop-on-error');
212
+ opt('tolerateEmptyQueues', '--tolerate-empty-queues');
213
+ opt('exitOnEmptyQueue', '--exit-on-empty-queue');
203
214
  opt('maxMemoryPercent', '--max-memory-percent');
204
215
  opt('imageCachePercent', '--image-cache-percent');
205
216
  opt('polling', '--polling');
package/src/index.js CHANGED
@@ -3,6 +3,8 @@ const { init, render } = require('@nexrender/core')
3
3
  const { getRenderingStatus } = require('@nexrender/types/job')
4
4
 
5
5
  const NEXRENDER_API_POLLING = process.env.NEXRENDER_API_POLLING || 30 * 1000;
6
+ const NEXRENDER_TOLERATE_EMPTY_QUEUES = process.env.NEXRENDER_TOLERATE_EMPTY_QUEUES;
7
+ var emptyReturns = 0;
6
8
 
7
9
  /* TODO: possibly add support for graceful shutdown */
8
10
  let active = true;
@@ -20,8 +22,14 @@ const nextJob = async (client, settings) => {
20
22
  );
21
23
 
22
24
  if (job && job.uid) {
25
+ emptyReturns = 0;
23
26
  return job
27
+ } else {
28
+ // no job was returned by the server. If enough checks have passed, and the exit option is set, deactivate the worker
29
+ emptyReturns++;
30
+ if (settings.exitOnEmptyQueue && emptyReturns > settings.tolerateEmptyQueues) active = false;
24
31
  }
32
+
25
33
  } catch (err) {
26
34
  if (settings.stopOnError) {
27
35
  throw err;
@@ -32,7 +40,7 @@ const nextJob = async (client, settings) => {
32
40
  }
33
41
  }
34
42
 
35
- await delay(settings.polling || NEXRENDER_API_POLLING)
43
+ if (active) await delay(settings.polling || NEXRENDER_API_POLLING)
36
44
  } while (active)
37
45
  }
38
46
 
@@ -52,14 +60,22 @@ const start = async (host, secret, settings, headers) => {
52
60
  if (typeof settings.tagSelector == 'string') {
53
61
  settings.tagSelector = settings.tagSelector.replace(/[^a-z0-9, ]/gi, '')
54
62
  }
55
-
63
+ // if there is no setting for how many empty queues to tolerate, make one from the
64
+ // environment variable, or the default (which is zero)
65
+ if (!(typeof settings.tolerateEmptyQueues == 'number')) {
66
+ settings.tolerateEmptyQueues = NEXRENDER_TOLERATE_EMPTY_QUEUES;
67
+ }
68
+
56
69
  const client = createClient({ host, secret, headers });
57
70
 
58
71
  do {
59
- let job = await nextJob(client, settings); {
60
- job.state = 'started';
61
- job.startedAt = new Date()
62
- }
72
+ let job = await nextJob(client, settings);
73
+
74
+ // if the worker has been deactivated, exit this loop
75
+ if (!active) break;
76
+
77
+ job.state = 'started';
78
+ job.startedAt = new Date()
63
79
 
64
80
  try {
65
81
  await client.updateJob(job.uid, job)