Skip to content

Commit

Permalink
update addEngagementFlag to handle reliableByBlock optional param
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxsong committed Jan 30, 2024
1 parent 1171382 commit 0e7675f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 53 deletions.
25 changes: 2 additions & 23 deletions src/firestore/app/appkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,9 @@ export class RoarAppkit {
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async updateEngagementFlags(flagNames: string[], markAsReliable = false) {
async updateEngagementFlags(flagNames: string[], markAsReliable = false, reliableByBlock = undefined) {
if (this._started) {
return this.run!.addEngagementFlags(flagNames, markAsReliable);
} else {
throw new Error('This run has not started. Use the startRun method first.');
}
}

/**
* Update the engagement flags for the current run in a block-based administration.
*
* @param {string[]} flagNames - The names of the engagement flags to add.
* @param {boolean} markAsReliable - Whether or not to mark the run as reliable, defaults to false
* @param {Object} reliableByBlock - Stores the reliability of the run by block
* For Example: {DEL: false, FSM: true, LSM: false}
* @method
* @async
*
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async updateEngagementFlagsByBlock(flagNames: string[], markAsReliable = false, reliableByBlock = {}) {
if (this._started) {
return this.run!.addEngagementFlagsByBlock(flagNames, markAsReliable, reliableByBlock);
return this.run!.addEngagementFlags(flagNames, markAsReliable, reliableByBlock);
} else {
throw new Error('This run has not started. Use the startRun method first.');
}
Expand Down
42 changes: 12 additions & 30 deletions src/firestore/app/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,14 @@ export class RoarRun {
* @async
* @param {string[]} engagementFlags - Engagement flags to add to the run
* @param {boolean} markAsReliable - Whether or not to mark the run as reliable, defaults to false
* @param {Object} reliableByBlock - Stores the reliability of the run by block
* This is an optional parameter that needs only to be passed in for block scoped tasks
* For Example: {DEL: false, FSM: true, LSM: false}
*
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async addEngagementFlags(engagementFlags: string[], markAsReliable = false) {
async addEngagementFlags(engagementFlags: string[], markAsReliable = false, reliableByBlock = undefined) {
if (!this.started) {
throw new Error('Run has not been started yet. Use the startRun method first.');
}
Expand All @@ -231,40 +234,19 @@ export class RoarRun {
}, {});

if (!this.aborted) {
return updateDoc(this.runRef, { engagementFlags: engagementObj, reliable: markAsReliable });
// In cases that the run is non-block-scoped and should only have the reliable attribute stored
if (reliableByBlock === undefined) {
return updateDoc(this.runRef, { engagementFlags: engagementObj, reliable: markAsReliable });
}
// In cases we want to store reliability by block, we need to store the reliable attribute as well as the reliableByBlock attribute
else {
return updateDoc(this.runRef, { engagementFlags: engagementObj, reliable: markAsReliable, reliableByBlock: reliableByBlock });
}
} else {
throw new Error('Run has already been aborted.');
}
}

/**
* Add engagement flags to a run.
* @method
* @async
* @param {string[]} engagementFlags - Engagement flags to add to the run
* @param {boolean} markAsReliable - Whether or not to mark the run as reliable, defaults to false
* @param {Object} reliableByBlock - Stores the reliability of the run by block
* For Example: {DEL: false, FSM: true, LSM: false}
*
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async addEngagementFlagsByBlock(engagementFlags: string[], markAsReliable = false, reliableByBlock = {}) {
if (!this.started) {
throw new Error('Run has not been started yet. Use the startRun method first.');
}

const engagementObj = engagementFlags.reduce((acc: { [x: string]: unknown }, flag) => {
acc[flag] = true;
return acc;
}, {});

if (!this.aborted) {
return updateDoc(this.runRef, { engagementFlags: engagementObj, reliable: markAsReliable, reliableByBlock: reliableByBlock });
} else {
throw new Error('Run has already been aborted.');
}
}

/**
* Mark this run as complete on Firestore
Expand Down

0 comments on commit 0e7675f

Please sign in to comment.