Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
feat(eyes-common): add notifyOnCompletion to BatchInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Sep 16, 2019
1 parent 58f895f commit bcffb40
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/eyes-common/lib/config/BatchInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { TypeUtils } = require('../utils/TypeUtils');
const { DateTimeUtils } = require('../utils/DateTimeUtils');

/**
* @typedef {{id: (string|undefined), name: (string|undefined), startedAt: (Date|string|undefined), sequenceName: (string|undefined)}} BatchInfoObject
* @typedef {{id: (string|undefined), name: (string|undefined), startedAt: (Date|string|undefined), sequenceName: (string|undefined), notifyOnCompletion: (boolean|undefined)}} BatchInfoObject
*/

/**
Expand Down Expand Up @@ -37,17 +37,24 @@ class BatchInfo {
*/
constructor(varArg1, varArg2, varArg3) {
if (varArg1 instanceof BatchInfo) {
return new BatchInfo({ id: varArg1.getId(), name: varArg1.getName(), startedAt: varArg1.getStartedAt(), sequenceName: varArg1.getSequenceName() });
return new BatchInfo({
id: varArg1.getId(),
name: varArg1.getName(),
startedAt: varArg1.getStartedAt(),
sequenceName: varArg1.getSequenceName(),
notifyOnCompletion: varArg1.getNotifyOnCompletion(),
});
}

if (TypeUtils.isString(varArg1)) {
return new BatchInfo({ id: varArg3, name: varArg1, startedAt: varArg2 });
}

let { id, name, startedAt, sequenceName } = varArg1 || {};
let { id, name, startedAt, sequenceName, notifyOnCompletion } = varArg1 || {};
ArgumentGuard.isString(id, 'batchId', false);
ArgumentGuard.isString(name, 'batchName', false);
ArgumentGuard.isString(sequenceName, 'sequenceName', false);
ArgumentGuard.isBoolean(notifyOnCompletion, 'notifyOnCompletion', false);

if (startedAt && !(startedAt instanceof Date)) {
ArgumentGuard.isString(startedAt, 'startedAt', false);
Expand All @@ -58,6 +65,7 @@ class BatchInfo {
this._name = name || GeneralUtils.getEnvValue('BATCH_NAME');
this._startedAt = startedAt || new Date();
this._sequenceName = sequenceName || GeneralUtils.getEnvValue('BATCH_SEQUENCE');
this._notifyOnCompletion = notifyOnCompletion || false;
}

/**
Expand Down Expand Up @@ -132,6 +140,22 @@ class BatchInfo {
return this;
}

/**
* @return {boolean} - Indicate whether notification should be sent on this batch completion.
*/
getNotifyOnCompletion() {
return this._notifyOnCompletion;
}

/**
* @param {boolean} notifyOnCompletion - Indicate whether notification should be sent on this batch completion.
* @return {this}
*/
setNotifyOnCompletion(notifyOnCompletion) {
this._notifyOnCompletion = notifyOnCompletion;
return this;
}

/**
* @override
*/
Expand Down

0 comments on commit bcffb40

Please sign in to comment.