Skip to content

Commit

Permalink
Rename and Reorganize Jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 10, 2024
1 parent 7e8a17b commit 840b731
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 387 deletions.
239 changes: 130 additions & 109 deletions source/SIL.AppBuilder.Portal/common/BullJobTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,136 +2,157 @@ import { Channels } from './build-engine-api/types.js';
import { RoleId } from './public/prisma.js';

export enum ScriptoriaJobType {
// Build Tasks
Build_Product = 'Build Product',
Build_Check = 'Check Product Build',
// Notification Tasks
Notify_Reviewers = 'Notify Reviewers',
// Product Tasks
Product_Create = 'Create Product',
// Project Tasks
Project_Create = 'Create Project',
Project_Check = 'Check Project Creation',
// Publishing Tasks
Publish_Product = 'Publish Product',
Publish_Check = 'Check Product Publish',
// System Tasks
System_CheckStatuses = 'Check System Statuses',
// Test
Test = 'Test',
ModifyUserTasks = 'ModifyUserTasks',
CreateProduct = 'CreateProduct',
BuildProduct = 'BuildProduct',
EmailReviewers = 'EmailReviewers',
PublishProduct = 'PublishProduct',
CheckBuildProduct = 'CheckBuildProduct',
CheckPublishProduct = 'CheckPublishProduct',
CheckSystemStatuses = 'CheckSystemStatuses',
CreateProject = 'CreateProject',
CheckCreateProject = 'CheckCreateProject'
// Other Tasks (for now)
UserTasks_Modify = 'Modify UserTasks'
}

export interface TestJob {
type: ScriptoriaJobType.Test;
time: number;
}

export enum UserTaskOp {
Delete = 'Delete',
Update = 'Update',
Create = 'Create',
Reassign = 'Reassign'
export namespace Build {
export interface Product {
type: ScriptoriaJobType.Build_Product;
productId: string;
targets?: string;
environment: { [key: string]: string };
}

export interface Check {
type: ScriptoriaJobType.Build_Check;
organizationId: number;
productId: string;
jobId: number;
buildId: number;
}
}

type UserTaskOpConfig = (
| ({
type: UserTaskOp.Delete | UserTaskOp.Create | UserTaskOp.Update;
} & (
| { by: 'All' }
| { by: 'Role'; roles: RoleId[] }
| {
by: 'UserId';
users: number[];
}
))
| {
type: UserTaskOp.Reassign;
by?: 'UserIdMapping' // <- This is literally just so TS doesn't complain
userMapping: { from: number; to: number }[];
}
);

// Using type here instead of interface for easier composition
export type ModifyUserTasksJob = (
| {
scope: 'Project';
projectId: number;
}
| {
scope: 'Product';
productId: string;
}
) & {
type: ScriptoriaJobType.ModifyUserTasks;
comment?: string; // just ignore comment for Delete and Reassign
operation: UserTaskOpConfig;
};

export interface CreateProductJob {
type: ScriptoriaJobType.CreateProduct;
productId: string;
export namespace Notify {
export interface Reviewers {
type: ScriptoriaJobType.Notify_Reviewers;
productId: string;
}
}

export interface BuildProductJob {
type: ScriptoriaJobType.BuildProduct;
productId: string;
targets?: string;
environment: { [key: string]: string };
export namespace Product {
export interface Create {
type: ScriptoriaJobType.Product_Create;
productId: string;
}
}

export interface EmailReviewersJob {
type: ScriptoriaJobType.EmailReviewers;
productId: string;
export namespace Project {
export interface Create {
type: ScriptoriaJobType.Project_Create;
projectId: number;
}

export interface Check {
type: ScriptoriaJobType.Project_Check;
workflowProjectId: number;
organizationId: number;
projectId: number;
}
}

export interface PublishProductJob {
type: ScriptoriaJobType.PublishProduct;
productId: string;
channel: Channels;
targets: string;
environment: { [key: string]: any };
export namespace UserTasks {
export enum OpType {
Delete = 'Delete',
Update = 'Update',
Create = 'Create',
Reassign = 'Reassign'
}

type Config =
| ({
type: OpType.Delete | OpType.Create | OpType.Update;
} & (
| { by: 'All' }
| { by: 'Role'; roles: RoleId[] }
| {
by: 'UserId';
users: number[];
}
))
| {
type: OpType.Reassign;
by?: 'UserIdMapping'; // <- This is literally just so TS doesn't complain
userMapping: { from: number; to: number }[];
};

// Using type here instead of interface for easier composition
export type Modify = (
| {
scope: 'Project';
projectId: number;
}
| {
scope: 'Product';
productId: string;
}
) & {
type: ScriptoriaJobType.UserTasks_Modify;
comment?: string; // just ignore comment for Delete and Reassign
operation: Config;
};
}

export interface CheckBuildProductJob {
type: ScriptoriaJobType.CheckBuildProduct;
organizationId: number;
productId: string;
jobId: number;
buildId: number;
export namespace Publish {
export interface Product {
type: ScriptoriaJobType.Publish_Product;
productId: string;
channel: Channels;
targets: string;
environment: { [key: string]: any };
}

export interface Check {
type: ScriptoriaJobType.Publish_Check;
organizationId: number;
productId: string;
jobId: number;
buildId: number;
releaseId: number;
}
}

export interface CheckPublishProductJob {
type: ScriptoriaJobType.CheckPublishProduct;
organizationId: number;
productId: string;
jobId: number;
buildId: number;
releaseId: number;
export namespace System {
export interface CheckStatuses {
type: ScriptoriaJobType.System_CheckStatuses;
}
}

export interface CheckSystemStatusesJob {
type: ScriptoriaJobType.CheckSystemStatuses;
}

export interface CreateProjectJob {
type: ScriptoriaJobType.CreateProject;
projectId: number;
}

export interface CheckCreateProjectJob {
type: ScriptoriaJobType.CheckCreateProject;
workflowProjectId: number;
organizationId: number;
projectId: number;
export interface Test {
type: ScriptoriaJobType.Test;
time: number;
}

export type ScriptoriaJob = JobTypeMap[keyof JobTypeMap];

export type JobTypeMap = {
[ScriptoriaJobType.Test]: TestJob;
[ScriptoriaJobType.ModifyUserTasks]: ModifyUserTasksJob;
[ScriptoriaJobType.CreateProduct]: CreateProductJob;
[ScriptoriaJobType.BuildProduct]: BuildProductJob;
[ScriptoriaJobType.EmailReviewers]: EmailReviewersJob;
[ScriptoriaJobType.PublishProduct]: PublishProductJob;
[ScriptoriaJobType.CheckBuildProduct]: CheckBuildProductJob;
[ScriptoriaJobType.CheckPublishProduct]: CheckPublishProductJob;
[ScriptoriaJobType.CheckSystemStatuses]: CheckSystemStatusesJob;
[ScriptoriaJobType.CreateProject]: CreateProjectJob;
[ScriptoriaJobType.CheckCreateProject]: CheckCreateProjectJob;
[ScriptoriaJobType.Build_Product]: Build.Product;
[ScriptoriaJobType.Build_Check]: Build.Check;
[ScriptoriaJobType.Notify_Reviewers]: Notify.Reviewers;
[ScriptoriaJobType.Product_Create]: Product.Create;
[ScriptoriaJobType.Project_Create]: Project.Create;
[ScriptoriaJobType.Project_Check]: Project.Check;
[ScriptoriaJobType.Publish_Product]: Publish.Product;
[ScriptoriaJobType.Publish_Check]: Publish.Check;
[ScriptoriaJobType.UserTasks_Modify]: UserTasks.Modify;
[ScriptoriaJobType.System_CheckStatuses]: System.CheckStatuses;
[ScriptoriaJobType.Test]: Test;
// Add more mappings here as needed
};
6 changes: 3 additions & 3 deletions source/SIL.AppBuilder.Portal/common/databaseProxy/Projects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Prisma } from '@prisma/client';
import {
ScriptoriaJobType,
UserTaskOp
UserTasks
} from '../BullJobTypes.js';
import { scriptoriaQueue } from '../bullmq.js';
import prisma from '../prisma.js';
Expand Down Expand Up @@ -72,11 +72,11 @@ export async function update(
// If the owner has changed, we need to reassign all the user tasks related to this project
if (ownerId && ownerId !== existing?.OwnerId) {
scriptoriaQueue.add(`Reassign tasks for Project #${id} (New Owner)`, {
type: ScriptoriaJobType.ModifyUserTasks,
type: ScriptoriaJobType.UserTasks_Modify,
scope: 'Project',
projectId: id,
operation: {
type: UserTaskOp.Reassign,
type: UserTasks.OpType.Reassign,
userMapping: [
{ from: existing.OwnerId, to: ownerId }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const DefaultWorkflow = setup({
assign({ instructions: 'waiting' }),
({ context }) => {
scriptoriaQueue.add(`Create Product #${context.productId}`, {
type: ScriptoriaJobType.CreateProduct,
type: ScriptoriaJobType.Product_Create,
productId: context.productId
},
{
Expand Down Expand Up @@ -472,7 +472,7 @@ export const DefaultWorkflow = setup({
}),
({ context }) => {
scriptoriaQueue.add(`Build Product #${context.productId}`, {
type: ScriptoriaJobType.BuildProduct,
type: ScriptoriaJobType.Build_Product,
productId: context.productId,
// TODO: assign targets
environment: context.environment
Expand Down Expand Up @@ -689,7 +689,7 @@ export const DefaultWorkflow = setup({
guard: { type: 'hasReviewers' },
actions: ({ context }) => {
scriptoriaQueue.add(`Email Reviewers (Product: ${context.productId})`, {
type: ScriptoriaJobType.EmailReviewers,
type: ScriptoriaJobType.Notify_Reviewers,
productId: context.productId
});
}
Expand All @@ -701,7 +701,7 @@ export const DefaultWorkflow = setup({
assign({ instructions: 'waiting' }),
({ context }) => {
scriptoriaQueue.add(`Publish Product #${context.productId}`, {
type: ScriptoriaJobType.PublishProduct,
type: ScriptoriaJobType.Publish_Product,
productId: context.productId,
// TODO: How should these values be determined?
channel: 'alpha',
Expand Down
8 changes: 4 additions & 4 deletions source/SIL.AppBuilder.Portal/common/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export class Workflow {
}
});
scriptoriaQueue.add(`Create UserTasks for Product #${productId}`, {
type: BullMQ.ScriptoriaJobType.ModifyUserTasks,
type: BullMQ.ScriptoriaJobType.UserTasks_Modify,
scope: 'Product',
productId: productId,
operation: {
type: BullMQ.UserTaskOp.Create,
type: BullMQ.UserTasks.OpType.Create,
by: 'All'
}
});
Expand Down Expand Up @@ -224,12 +224,12 @@ export class Workflow {
}
});
scriptoriaQueue.add(`Update UserTasks for Product #${this.productId}`, {
type: BullMQ.ScriptoriaJobType.ModifyUserTasks,
type: BullMQ.ScriptoriaJobType.UserTasks_Modify,
scope: 'Product',
productId: this.productId,
comment: event.event.comment || undefined,
operation: {
type: BullMQ.UserTaskOp.Update,
type: BullMQ.UserTasks.OpType.Update,
by: 'All'
}
});
Expand Down
Loading

0 comments on commit 840b731

Please sign in to comment.