Skip to content

Commit

Permalink
Create configuration object for default retries
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 24, 2024
1 parent a4df123 commit ff09eed
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
16 changes: 16 additions & 0 deletions source/SIL.AppBuilder.Portal/common/BullJobTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { Channels } from './build-engine-api/types.js';
import { RoleId } from './public/prisma.js';

interface RetryOptions {
readonly attempts: number;
readonly backoff: {
readonly type: string;
readonly delay: number;
}
}

export const Retry5e5: RetryOptions = {
attempts: 5,
backoff: {
type: 'exponential',
delay: 5000 // 5 seconds
}
};

export enum ScriptoriaJobType {
// Build Tasks
Build_Product = 'Build Product',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ async function deleteProduct(productId: string) {
organizationId: product.Project.OrganizationId,
workflowJobId: product.WorkflowJobId
},
{
attempts: 5,
backoff: {
type: 'exponential',
delay: 5000 // 5 seconds
}
}
BullMQ.Retry5e5
);
return prisma.$transaction([
prisma.workflowInstances.delete({
Expand Down
26 changes: 4 additions & 22 deletions source/SIL.AppBuilder.Portal/common/workflow/default-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
WorkflowEvent
} from '../public/workflow.js';
import { RoleId } from '../public/prisma.js';
import { queues } from '../index.js';
import { BullMQ, queues } from '../index.js';
import { ScriptoriaJobType } from '../BullJobTypes.js';

/**
Expand Down Expand Up @@ -312,13 +312,7 @@ export const DefaultWorkflow = setup({
type: ScriptoriaJobType.Product_Create,
productId: context.productId
},
{
attempts: 5,
backoff: {
type: 'exponential',
delay: 5000 // 5 seconds
}
});
BullMQ.Retry5e5);
}
],
on: {
Expand Down Expand Up @@ -478,13 +472,7 @@ export const DefaultWorkflow = setup({
// TODO: assign targets
environment: context.environment
},
{
attempts: 5,
backoff: {
type: 'exponential',
delay: 5000 // 5 seconds
}
});
BullMQ.Retry5e5);
}
],
on: {
Expand Down Expand Up @@ -709,13 +697,7 @@ export const DefaultWorkflow = setup({
targets: 'google-play',
environment: context.environment
},
{
attempts: 5,
backoff: {
type: 'exponential',
delay: 5000 // 5 seconds
}
});
BullMQ.Retry5e5);
}
],
on: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const actions: Actions = {
// TODO: Return/Display error messages
if (!form.valid) return fail(400, { form, ok: false });
if (isNaN(parseInt(event.params.id))) return fail(400, { form, ok: false });
const timestamp = (new Date()).toString();
const timestamp = new Date();
const project = await DatabaseWrites.projects.create({
OrganizationId: parseInt(event.params.id),
Name: form.data.Name,
Expand All @@ -81,7 +81,8 @@ export const actions: Actions = {
queues.scriptoria.add(`Create Project #${project}`, {
type: BullMQ.ScriptoriaJobType.Project_Create,
projectId: project as number
});
},
BullMQ.Retry5e5);
}

return { form, ok: project !== false };
Expand Down

0 comments on commit ff09eed

Please sign in to comment.