Skip to content

Commit

Permalink
added name to worker and api clients
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Jan 29, 2024
1 parent a891a99 commit 4ebff2d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/nexrender-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const fetchAgent = typeof process == 'undefined' ? null : { // eslint-disable-li
https: require('https').Agent,
}

const createClient = ({ host, secret, polling, headers }) => {
const pkg = require('../package.json')

const createClient = ({ host, secret, polling, headers, name }) => {
const wrappedFetch = async (path, options) => {
options = options || {}
const defaultHeaders = {};
Expand All @@ -26,6 +28,12 @@ const createClient = ({ host, secret, polling, headers }) => {
options.headers['nexrender-secret'] = secret
}

if (name) {
options.headers['nexrender-name'] = name
}

options.headers['user-agent'] = ('nexrender-api/' + pkg.version + ' ' + (options.headers['user-agent'] || '')).trim()

if (typeof process != 'undefined') {
// NOTE: keepalive is enabled by default in node-fetch, so we need to disable it because of a bug
// related to an invalidated session by the client
Expand Down
1 change: 1 addition & 0 deletions packages/nexrender-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const render = (jobConfig, settings = {}) => {
.then(job => state(job, settings, postrender, 'postrender'))
.then(job => state(job, settings, cleanup, 'cleanup'))
.catch(e => {
console.log('catching the error internally')
state(job, settings, cleanup, 'cleanup');
throw e;
});
Expand Down
7 changes: 7 additions & 0 deletions packages/nexrender-worker/src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const args = arg({
'--cleanup': Boolean,

'--host': String,
'--name': String,
'--secret': String,

'--binary': String,
Expand Down Expand Up @@ -49,6 +50,7 @@ const args = arg({
'-t': '--tag-selector',
'-c': '--cleanup',
'-h': '--help',
'-n': '--name',
'-s': '--secret',
'-b': '--binary',
'-w': '--workpath',
Expand Down Expand Up @@ -86,6 +88,10 @@ if (args['--help']) {
specify which host {cyan nexrender-server} is running at,
and where all api requests will be forwarded to
-n, --name {underline unique_worker_name}
specify which name the {cyan nexrender-worker} will have,
and how it will be identified in the {cyan nexrender-server}
-s, --secret {underline secret_string} specify a secret that will be required for every
incoming http request to validate again
Expand Down Expand Up @@ -199,6 +205,7 @@ if (settings.hasOwnProperty('ae-params')) {
settings['aeParams'] = settings['ae-params']
}

opt('name', '--name');
opt('binary', '--binary');
opt('workpath', '--workpath');
opt('no-license', '--no-license');
Expand Down
6 changes: 5 additions & 1 deletion packages/nexrender-worker/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { createClient } = require('@nexrender/api')
const { init, render } = require('@nexrender/core')
const { getRenderingStatus } = require('@nexrender/types/job')
const pkg = require('../package.json')

const NEXRENDER_API_POLLING = process.env.NEXRENDER_API_POLLING || 30 * 1000;
const NEXRENDER_TOLERATE_EMPTY_QUEUES = process.env.NEXRENDER_TOLERATE_EMPTY_QUEUES;
Expand Down Expand Up @@ -71,7 +72,10 @@ const start = async (host, secret, settings, headers) => {
settings.tolerateEmptyQueues = NEXRENDER_TOLERATE_EMPTY_QUEUES;
}

const client = createClient({ host, secret, headers });
headers = headers || {};
headers['user-agent'] = ('nexrender-worker/' + pkg.version + ' ' + (headers['user-agent'] || '')).trim();

const client = createClient({ host, secret, headers, name: settings.name });

settings.track('Worker Started', {
worker_tags_set: !!settings.tagSelector,
Expand Down

0 comments on commit 4ebff2d

Please sign in to comment.