Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/lib/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
"prodDefs_emptyType": "Need to select an Application Type",
"prodDefs_emptyFlow": "Need to select a Workflow definition",
"prodDefs_noFlow": "No Workflow Required",
"prodDefs_startAt": "Start Manual Rebuilds at",
"stores_emptyStoreType": "Need to select a store type for this store",
"storeTypes_title": "Store Types",
"storeTypes_name": "Store Type Name",
Expand Down
1 change: 1 addition & 0 deletions src/lib/locales/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"prodDefs_emptyType": "Necesita seleccionar un tipo de aplicación",
"prodDefs_emptyFlow": "Need to select a Workflow definition",
"prodDefs_noFlow": "No Workflow Required",
"prodDefs_startAt": "Iniciar reconstrucciones manuales en",
"storeTypes_title": "Tipos de tienda",
"storeTypes_name": "Store Type Name",
"storeTypes_add": "Añadir tipo de tienda",
Expand Down
1 change: 1 addition & 0 deletions src/lib/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@
"prodDefs_emptyType": "Need to select an Application Type",
"prodDefs_emptyFlow": "Need to select a Workflow definition",
"prodDefs_noFlow": "No Workflow Required",
"prodDefs_startAt": "Start Manual Rebuilds at",
"stores_emptyStoreType": "Need to select a store type for this store",
"storeTypes_title": "Store Types",
"storeTypes_name": "Store Type Name",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ProductDefinitions" ADD COLUMN "StartManualRebuildAt" TEXT;
1 change: 1 addition & 0 deletions src/lib/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ model ProductDefinitions {
Description String?
WorkflowId Int
RebuildWorkflowId Int?
StartManualRebuildAt String?
RepublishWorkflowId Int?
Properties String?
OrganizationProductDefinitions OrganizationProductDefinitions[]
Expand Down
9 changes: 8 additions & 1 deletion src/lib/products/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ProductTransitionType, WorkflowType } from '$lib/prisma';
import { BullMQ, getQueues } from '$lib/server/bullmq';
import { DatabaseReads, DatabaseWrites } from '$lib/server/database';
import { Workflow } from '$lib/server/workflow';
import type { WorkflowState } from '$lib/workflowTypes';
import { ProductActionType } from '.';

export async function doProductAction(productId: string, action: ProductActionType) {
Expand All @@ -21,6 +22,7 @@ export async function doProductAction(productId: string, action: ProductActionTy
WorkflowOptions: true
}
},
StartManualRebuildAt: true,
RepublishWorkflow: {
select: {
Type: true,
Expand Down Expand Up @@ -49,7 +51,12 @@ export async function doProductAction(productId: string, action: ProductActionTy
await Workflow.create(productId, {
productType: product.ProductDefinition[flowType].ProductType,
options: new Set(product.ProductDefinition[flowType].WorkflowOptions),
workflowType: product.ProductDefinition[flowType].Type
workflowType: product.ProductDefinition[flowType].Type,
// ISSUE #1324 use isAutomatic here
start:
(action === 'rebuild' &&
(product.ProductDefinition.StartManualRebuildAt as WorkflowState)) ||
undefined
});
}
break;
Expand Down
33 changes: 32 additions & 1 deletion src/lib/server/job-executors/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export async function migrate(job: Job<BullMQ.System.Migrate>): Promise<unknown>
).map(({ Id }) => DatabaseWrites.workflowInstances.markProcessFinalized(Id))
);

job.updateProgress(70);
job.updateProgress(50);
// Update WorkflowDefinitions ProductType and WorkflowOptions
const workflowDefsNeedUpdate =
(await DatabaseReads.workflowDefinitions.count({
Expand Down Expand Up @@ -618,6 +618,36 @@ export async function migrate(job: Job<BullMQ.System.Migrate>): Promise<unknown>
await DatabaseWrites.workflowDefinitions.updateMany(def);
}
}
job.updateProgress(55);
const prodDefsNeedUpdate = await DatabaseReads.productDefinitions.findMany({
where: { Properties: { contains: '"ShouldExecute":' } },
select: { Id: true, Properties: true }
});
if (prodDefsNeedUpdate.length) {
for (const prodDef of prodDefsNeedUpdate) {
const prefix = `ProductDefinition Id=${prodDef.Id}`;
try {
const parsed = JSON.parse(prodDef.Properties!);
const targets = Object.keys(parsed['ShouldExecute']);
if (targets.length === 1) {
await DatabaseWrites.productDefinitions.update({
where: { Id: prodDef.Id },
data: {
StartManualRebuildAt: targets[0],
// Remove ShouldExecute from Properties
Properties: JSON.stringify({ ...parsed, ShouldExecute: undefined })
}
});
} else {
job.log(
`${prefix} Multiple ShouldExecute targets: ${JSON.stringify(parsed['ShouldExecute'], null, 2)}`
);
}
} catch (e) {
job.log(`${prefix} Error: ${e}`);
}
}
}
job.updateProgress(60);

// 4. Populate Product.PackageName
Expand Down Expand Up @@ -699,6 +729,7 @@ export async function migrate(job: Job<BullMQ.System.Migrate>): Promise<unknown>
migrationErrors,
orphanedWPIs: orphanedInstances.reduce((p, c) => p + (c?.at(-1)?.count ?? 0), 0),
updatedWorkflowDefinitions: workflowDefsNeedUpdate,
updatedProductDefinitions: !!prodDefsNeedUpdate,
updatedPackages,
deletedUsers: {
users: deletedUsers,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/workflowTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export type WorkflowInstanceContext = {
)[];
includeReviewers: boolean;
includeArtifacts: ArtifactLists | null;
start?: WorkflowState;
start?: WorkflowState; // keep here too so it is still persisted in DB
environment: Environment;
};

Expand Down Expand Up @@ -181,6 +181,7 @@ export type WorkflowConfig = {
options: Set<WorkflowOptions>;
productType: ProductType;
workflowType: WorkflowType;
start?: WorkflowState;
};

export type WorkflowInput = WorkflowConfig & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import type { Actions, PageServerLoad } from './$types';
import { localizeHref } from '$lib/paraglide/runtime';
import { DatabaseReads, DatabaseWrites } from '$lib/server/database';
import { idSchema, propertiesSchema } from '$lib/valibot';
import { WorkflowState } from '$lib/workflowTypes';

const editSchema = v.object({
id: idSchema,
name: v.nullable(v.string()),
applicationType: idSchema,
workflow: idSchema,
rebuildWorkflow: v.nullable(idSchema),
startManualRebuildAt: v.nullable(v.literal(String(WorkflowState.Synchronize_Data))),
republishWorkflow: v.nullable(idSchema),
description: v.nullable(v.string()),
properties: propertiesSchema
Expand Down Expand Up @@ -40,6 +42,7 @@ export const load = (async ({ url, locals }) => {
applicationType: data.TypeId,
workflow: data.WorkflowId,
rebuildWorkflow: data.RebuildWorkflowId,
startManualRebuildAt: data.StartManualRebuildAt,
republishWorkflow: data.RepublishWorkflowId,
description: data.Description,
properties: data.Properties
Expand All @@ -65,6 +68,7 @@ export const actions = {
Name: form.data.name,
WorkflowId: form.data.workflow,
RebuildWorkflowId: form.data.rebuildWorkflow,
StartManualRebuildAt: form.data.startManualRebuildAt,
RepublishWorkflowId: form.data.republishWorkflow,
Description: form.data.description,
Properties: form.data.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { getLocale, localizeHref } from '$lib/paraglide/runtime';
import { toast } from '$lib/utils';
import { byName } from '$lib/utils/sorting';
import { WorkflowState } from '$lib/workflowTypes';

interface Props {
data: PageData;
Expand Down Expand Up @@ -95,6 +96,19 @@
</select>
<span class="validator-hint">&nbsp;</span>
</LabeledFormInput>
{#if $form.rebuildWorkflow}
<LabeledFormInput key="prodDefs_startAt">
<select
class="select select-bordered"
name="startManualRebuildAt"
bind:value={$form.startManualRebuildAt}
>
<option value={null}>{WorkflowState.Product_Build}</option>
<option value={WorkflowState.Synchronize_Data}>{WorkflowState.Synchronize_Data}</option>
</select>
<span class="validator-hint">&nbsp;</span>
</LabeledFormInput>
{/if}
<LabeledFormInput key="prodDefs_republishFlow">
<select
class="select select-bordered"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import * as v from 'valibot';
import type { Actions, PageServerLoad } from './$types';
import { DatabaseReads, DatabaseWrites } from '$lib/server/database';
import { propertiesSchema } from '$lib/valibot';
import { WorkflowState } from '$lib/workflowTypes';

const createSchema = v.object({
name: v.nullable(v.string()),
applicationType: v.pipe(v.number(), v.minValue(1), v.integer()),
workflow: v.pipe(v.number(), v.minValue(1), v.integer()),
rebuildWorkflow: v.nullable(v.pipe(v.number(), v.minValue(1), v.integer())),
startManualRebuildAt: v.nullable(v.literal(String(WorkflowState.Synchronize_Data))),
republishWorkflow: v.nullable(v.pipe(v.number(), v.minValue(1), v.integer())),
description: v.nullable(v.string()),
properties: propertiesSchema
Expand Down Expand Up @@ -39,6 +41,7 @@ export const actions = {
TypeId: form.data.applicationType,
WorkflowId: form.data.workflow,
RebuildWorkflowId: form.data.rebuildWorkflow,
StartManualRebuildAt: form.data.startManualRebuildAt,
RepublishWorkflowId: form.data.republishWorkflow,
Description: form.data.description,
Properties: form.data.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { getLocale, localizeHref } from '$lib/paraglide/runtime';
import { toast } from '$lib/utils';
import { byName } from '$lib/utils/sorting';
import { WorkflowState } from '$lib/workflowTypes';

interface Props {
data: PageData;
Expand Down Expand Up @@ -93,6 +94,19 @@
</select>
<span class="validator-hint">&nbsp;</span>
</LabeledFormInput>
{#if $form.rebuildWorkflow}
<LabeledFormInput key="prodDefs_startAt">
<select
class="select select-bordered"
name="startManualRebuildAt"
bind:value={$form.startManualRebuildAt}
>
<option value={null}>{WorkflowState.Product_Build}</option>
<option value={WorkflowState.Synchronize_Data}>{WorkflowState.Synchronize_Data}</option>
</select>
<span class="validator-hint">&nbsp;</span>
</LabeledFormInput>
{/if}
<LabeledFormInput key="prodDefs_republishFlow">
<select
class="select select-bordered"
Expand Down
Loading