From 0e7675fff4ff704f0378277454826c46a28c666c Mon Sep 17 00:00:00 2001 From: Lucas Song Date: Tue, 30 Jan 2024 10:03:46 -0800 Subject: [PATCH] update addEngagementFlag to handle reliableByBlock optional param --- src/firestore/app/appkit.ts | 25 ++-------------------- src/firestore/app/run.ts | 42 +++++++++++-------------------------- 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/src/firestore/app/appkit.ts b/src/firestore/app/appkit.ts index b9ffb028..c1a781ec 100644 --- a/src/firestore/app/appkit.ts +++ b/src/firestore/app/appkit.ts @@ -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.'); } diff --git a/src/firestore/app/run.ts b/src/firestore/app/run.ts index 6d3d0aff..0d7ffdff 100644 --- a/src/firestore/app/run.ts +++ b/src/firestore/app/run.ts @@ -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.'); } @@ -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