Skip to content

Commit

Permalink
fix(worker): cron validation
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Jan 21, 2025
1 parent 00258c9 commit 2008d72
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions apps/worker/src/app/workflow/usecases/add-job/add-job.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ export class AddJob {
const filterVariables = shouldRun.variables;
const filtered = !shouldRun.passed;

let digestResult: {
digestAmount: number;
digestCreationResult: DigestCreationResultEnum;
cronExpression?: string;
} | null = null;

if (job.type === StepTypeEnum.DIGEST) {
const digestResult = await this.handleDigest(command, filterVariables, job, digestAmount, filtered);
digestResult = await this.handleDigest(command, filterVariables, job, digestAmount, filtered);

if (isShouldHaltJobExecution(digestResult.digestCreationResult)) {
return;
Expand All @@ -161,17 +167,18 @@ export class AddJob {

const delay = this.getExecutionDelayAmount(filtered, digestAmount, delayAmount);

await this.validateDeferDuration(delay, job, command);
await this.validateDeferDuration(delay, job, command, digestResult?.cronExpression);

await this.queueJob(job, delay);
}

private async validateDeferDuration(delay: number, job: JobEntity, command: AddJobCommand) {
private async validateDeferDuration(delay: number, job: JobEntity, command: AddJobCommand, cronExpression?: string) {
const errors = await this.tierRestrictionsValidateUsecase.execute(
TierRestrictionsValidateCommand.create({
deferDurationMs: delay,
stepType: job.type,
organizationId: command.organizationId,
cron: cronExpression,
})
);

Expand Down Expand Up @@ -387,7 +394,7 @@ export class AddJob {
await this.handleDigestSkip(command, job);
}

return { digestAmount, digestCreationResult };
return { digestAmount, digestCreationResult, cronExpression: bridgeResponse?.outputs?.cron as string | undefined };
}

private mapBridgeTimedDigestAmount(bridgeResponse: ExecuteOutput | null): number | null {
Expand Down

0 comments on commit 2008d72

Please sign in to comment.