-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added option to configure newJobCheckInterval config per subscription
- Loading branch information
Showing
3 changed files
with
95 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,116 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
checkConfig | ||
applyConfig, | ||
applyNewJobCheckInterval | ||
}; | ||
|
||
function checkConfig(config) { | ||
assert(config && (typeof config == 'object' || typeof config == 'string'), | ||
'configuration assert: string or config object is required to connect to postgres'); | ||
function applyConfig(config) { | ||
|
||
if(typeof config == 'string') | ||
config = {connectionString: config}; | ||
else { | ||
assert(config.database && config.user && 'password' in config, | ||
'configuration assert: not enough database settings to connect to PostgreSQL'); | ||
assert(config && (typeof config == 'object' || typeof config == 'string'), | ||
'configuration assert: string or config object is required to connect to postgres'); | ||
|
||
config.host = config.host || '127.0.0.1'; | ||
config.port = config.port || 5432; | ||
} | ||
config = applyDatabaseConfig(config); | ||
config = applyNewJobCheckInterval(config); | ||
config = applyExpireConfig(config); | ||
config = applyArchiveConfig(config); | ||
config = applyUuidConfig(config); | ||
|
||
if(config.schema){ | ||
assert(typeof config.schema == 'string', 'configuration assert: schema must be a string'); | ||
assert(config.schema.length <= 50, 'configuration assert: schema name cannot exceed 50 characters'); | ||
assert(!/\W/.test(config.schema), `configuration assert: ${config.schema} cannot be used as a schema. Only alphanumeric characters and underscores are allowed`); | ||
} | ||
return config; | ||
|
||
assert(!('newJobCheckInterval' in config) || config.newJobCheckInterval >=100, | ||
'configuration assert: newJobCheckInterval must be at least every 100ms'); | ||
|
||
assert(!('newJobCheckIntervalSeconds' in config) || config.newJobCheckIntervalSeconds >=1, | ||
'configuration assert: newJobCheckIntervalSeconds must be at least every second'); | ||
} | ||
|
||
function applyDatabaseConfig(config) { | ||
|
||
assert(!('expireCheckInterval' in config) || config.expireCheckInterval >=100, | ||
'configuration assert: expireCheckInterval must be at least every 100ms'); | ||
if(typeof config == 'string') { | ||
config = {connectionString: config}; | ||
} | ||
else { | ||
assert(config.database && config.user && 'password' in config, | ||
'configuration assert: not enough database settings to connect to PostgreSQL'); | ||
|
||
assert(!('expireCheckIntervalSeconds' in config) || config.expireCheckIntervalSeconds >=1, | ||
'configuration assert: expireCheckIntervalSeconds must be at least every second'); | ||
config.host = config.host || '127.0.0.1'; | ||
config.port = config.port || 5432; | ||
} | ||
|
||
assert(!('expireCheckIntervalMinutes' in config) || config.expireCheckIntervalMinutes >=1, | ||
'configuration assert: expireCheckIntervalMinutes must be at least every minute'); | ||
if(config.schema){ | ||
assert(typeof config.schema == 'string', 'configuration assert: schema must be a string'); | ||
assert(config.schema.length <= 50, 'configuration assert: schema name cannot exceed 50 characters'); | ||
assert(!/\W/.test(config.schema), `configuration assert: ${config.schema} cannot be used as a schema. Only alphanumeric characters and underscores are allowed`); | ||
} | ||
|
||
config.schema = config.schema || 'pgboss'; | ||
|
||
assert(!('archiveCheckInterval' in config) || config.archiveCheckInterval >=100, | ||
'configuration assert: archiveCheckInterval must be at least every 100ms'); | ||
assert(!('poolSize' in config) || config.poolSize >=1, | ||
'configuration assert: poolSize must be at least 1'); | ||
|
||
assert(!('archiveCheckIntervalSeconds' in config) || config.archiveCheckIntervalSeconds >=1, | ||
'configuration assert: archiveCheckIntervalSeconds must be at least every second'); | ||
config.poolSize = config.poolSize || 10; | ||
|
||
assert(!('archiveCheckIntervalMinutes' in config) || config.archiveCheckIntervalMinutes >=1, | ||
'configuration assert: archiveCheckIntervalMinutes must be at least every minute'); | ||
return config; | ||
} | ||
|
||
function applyNewJobCheckInterval(config) { | ||
assert(!('newJobCheckInterval' in config) || config.newJobCheckInterval >=100, | ||
'configuration assert: newJobCheckInterval must be at least every 100ms'); | ||
|
||
assert(!('archiveCompletedJobsEvery' in config) || typeof config.archiveCompletedJobsEvery == 'string', | ||
'configuration assert: archiveCompletedJobsEvery should be a readable PostgreSQL interval such as "1 day"'); | ||
assert(!('newJobCheckIntervalSeconds' in config) || config.newJobCheckIntervalSeconds >=1, | ||
'configuration assert: newJobCheckIntervalSeconds must be at least every second'); | ||
|
||
config.newJobCheckInterval = | ||
('newJobCheckIntervalSeconds' in config) ? config.newJobCheckIntervalSeconds * 1000 | ||
: ('newJobCheckInterval' in config) ? config.newJobCheckInterval | ||
: 1000; // default is 1 second | ||
|
||
assert(!('uuid' in config) || config.uuid == 'v1' || config.uuid == 'v4', 'configuration assert: uuid option only supports v1 or v4'); | ||
return config; | ||
} | ||
|
||
assert(!('poolSize' in config) || config.poolSize >=1, | ||
'configuration assert: poolSize must be at least 1'); | ||
function applyExpireConfig(config){ | ||
assert(!('expireCheckInterval' in config) || config.expireCheckInterval >=100, | ||
'configuration assert: expireCheckInterval must be at least every 100ms'); | ||
|
||
config.uuid = config.uuid || 'v1'; | ||
config.schema = config.schema || 'pgboss'; | ||
config.poolSize = config.poolSize || 10; | ||
assert(!('expireCheckIntervalSeconds' in config) || config.expireCheckIntervalSeconds >=1, | ||
'configuration assert: expireCheckIntervalSeconds must be at least every second'); | ||
|
||
config.newJobCheckInterval = | ||
('newJobCheckIntervalSeconds' in config) ? config.newJobCheckIntervalSeconds * 1000 | ||
: ('newJobCheckInterval' in config) ? config.newJobCheckInterval | ||
: 1000; // default is 1 second | ||
assert(!('expireCheckIntervalMinutes' in config) || config.expireCheckIntervalMinutes >=1, | ||
'configuration assert: expireCheckIntervalMinutes must be at least every minute'); | ||
|
||
config.expireCheckInterval = | ||
('expireCheckIntervalMinutes' in config) ? config.expireCheckIntervalMinutes * 60 * 1000 | ||
: ('expireCheckIntervalSeconds' in config) ? config.expireCheckIntervalSeconds * 1000 | ||
config.expireCheckInterval = | ||
('expireCheckIntervalMinutes' in config) ? config.expireCheckIntervalMinutes * 60 * 1000 | ||
: ('expireCheckIntervalSeconds' in config) ? config.expireCheckIntervalSeconds * 1000 | ||
: ('expireCheckInterval' in config) ? config.expireCheckInterval | ||
: 60 * 1000; // default is 1 minute | ||
: 60 * 1000; // default is 1 minute | ||
|
||
return config; | ||
} | ||
|
||
config.archiveCheckInterval = | ||
('archiveCheckIntervalMinutes' in config) ? config.archiveCheckIntervalMinutes * 60 * 1000 | ||
: ('archiveCheckIntervalSeconds' in config) ? config.archiveCheckIntervalSeconds * 1000 | ||
function applyArchiveConfig(config) { | ||
assert(!('archiveCheckInterval' in config) || config.archiveCheckInterval >=100, | ||
'configuration assert: archiveCheckInterval must be at least every 100ms'); | ||
|
||
assert(!('archiveCheckIntervalSeconds' in config) || config.archiveCheckIntervalSeconds >=1, | ||
'configuration assert: archiveCheckIntervalSeconds must be at least every second'); | ||
|
||
assert(!('archiveCheckIntervalMinutes' in config) || config.archiveCheckIntervalMinutes >=1, | ||
'configuration assert: archiveCheckIntervalMinutes must be at least every minute'); | ||
|
||
config.archiveCheckInterval = | ||
('archiveCheckIntervalMinutes' in config) ? config.archiveCheckIntervalMinutes * 60 * 1000 | ||
: ('archiveCheckIntervalSeconds' in config) ? config.archiveCheckIntervalSeconds * 1000 | ||
: ('archiveCheckInterval' in config) ? config.archiveCheckInterval | ||
: 60 * 60 * 1000; // default is 1 hour | ||
: 60 * 60 * 1000; // default is 1 hour | ||
|
||
|
||
assert(!('archiveCompletedJobsEvery' in config) || typeof config.archiveCompletedJobsEvery == 'string', | ||
'configuration assert: archiveCompletedJobsEvery should be a readable PostgreSQL interval such as "1 day"'); | ||
|
||
config.archiveCompletedJobsEvery = config.archiveCompletedJobsEvery || '1 day'; | ||
|
||
return config; | ||
} | ||
|
||
config.archiveCompletedJobsEvery = config.archiveCompletedJobsEvery || '1 day'; | ||
function applyUuidConfig(config) { | ||
assert(!('uuid' in config) || config.uuid == 'v1' || config.uuid == 'v4', 'configuration assert: uuid option only supports v1 or v4'); | ||
config.uuid = config.uuid || 'v1'; | ||
|
||
return config; | ||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters