Skip to content

fix: use challenge scheduler only for f2fs #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/domain/Challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {

const newChallenge = await super.create(challenge, metadata);

if (input.phases && input.phases.length) {
if (input.phases && input.phases.length && this.shouldUseScheduler(newChallenge)) {
await ChallengeScheduler.schedule(newChallenge.id, input.phases);
}

Expand Down Expand Up @@ -329,7 +329,11 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
metadata
);

if (input.phaseUpdate?.phases && input.phaseUpdate.phases.length) {
if (
input.phaseUpdate?.phases &&
input.phaseUpdate.phases.length &&
this.shouldUseScheduler(challenge)
) {
await ChallengeScheduler.schedule(challenge.id, input.phaseUpdate.phases);
}

Expand All @@ -341,8 +345,15 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
input: UpdateChallengeInputForACL_UpdateInputForACL
): Promise<void> {
const updatedBy = "tcwebservice"; // TODO: Extract from interceptors
let challenge: Challenge | undefined = undefined;
const id = scanCriteria[0].value;

const challenge: Challenge | undefined =
!_.isUndefined(input.legacy) ||
!_.isUndefined(input.phaseToClose) ||
(input.phases?.phases && input.phases.phases.length)
? await this.lookup(DomainHelper.getLookupCriteria("id", id))
: undefined;

const data: IUpdateDataFromACL = {};
let raiseEvent = false;

Expand All @@ -369,15 +380,7 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
}

if (!_.isUndefined(input.legacy)) {
if (_.isUndefined(challenge)) {
try {
challenge = await this.lookup(DomainHelper.getLookupCriteria("id", id));
} catch (err) {
console.error(err);
throw err;
}
}
data.legacy = _.assign({}, challenge.legacy, input.legacy);
data.legacy = _.assign({}, challenge?.legacy, input.legacy);
}

if (!_.isUndefined(input.prizeSets)) {
Expand Down Expand Up @@ -418,11 +421,11 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {

await super.update(scanCriteria, dynamoUpdate);

if (input.phases?.phases && input.phases.phases.length) {
if (input.phases?.phases && input.phases.phases.length && this.shouldUseScheduler(challenge!)) {
await ChallengeScheduler.schedule(id, input.phases.phases);
}

if (!_.isUndefined(input.phaseToClose)) {
if (!_.isUndefined(input.phaseToClose) && this.shouldUseScheduler(challenge!)) {
await ChallengeScheduler.schedulePhaseOperation(id, input.phaseToClose, "close");
}

Expand Down Expand Up @@ -481,6 +484,11 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
delete overview.totalPrizesInCents;
}
}

private shouldUseScheduler(challenge: Challenge) {
// Use scheduler only for legacy code F2Fs
return challenge?.legacy?.subTrack === "FIRST_2_FINISH" && !challenge?.legacy.pureV5Task;
}
}

interface IUpdateDataFromACL {
Expand Down