360 workflow implement workflow cron triggers frontend 2 (#10051)
as title, closes https://github.com/twentyhq/core-team-issues/issues/360 ## Cron Setting behavior https://github.com/user-attachments/assets/0de3a8b9-d899-4455-a945-20c7541c3053 ## Cron running behavior https://github.com/user-attachments/assets/4c33f167-857c-4fcb-9dbe-0f9b661c9e61
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
import { getCronTriggerDefaultSettings } from '@/workflow/workflow-trigger/utils/getCronTriggerDefaultSettings';
|
||||
|
||||
describe('getCronTriggerDefaultSettings', () => {
|
||||
it('returns correct settings for HOURS interval', () => {
|
||||
const result = getCronTriggerDefaultSettings('HOURS');
|
||||
expect(result).toEqual({
|
||||
schedule: { hour: 1, minute: 0 },
|
||||
type: 'HOURS',
|
||||
outputSchema: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct settings for MINUTES interval', () => {
|
||||
const result = getCronTriggerDefaultSettings('MINUTES');
|
||||
expect(result).toEqual({
|
||||
schedule: { minute: 1 },
|
||||
type: 'MINUTES',
|
||||
outputSchema: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct settings for CUSTOM interval', () => {
|
||||
const DEFAULT_CRON_PATTERN = '0 */1 * * *';
|
||||
const result = getCronTriggerDefaultSettings('CUSTOM');
|
||||
expect(result).toEqual({
|
||||
pattern: DEFAULT_CRON_PATTERN,
|
||||
type: 'CUSTOM',
|
||||
outputSchema: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('throws an error for an invalid interval', () => {
|
||||
// @ts-expect-error Testing invalid input
|
||||
expect(() => getCronTriggerDefaultSettings('INVALID')).toThrowError(
|
||||
'Invalid cron trigger interval',
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,39 @@
|
||||
import { CronTriggerInterval } from '@/workflow/workflow-trigger/constants/CronTriggerIntervalOptions';
|
||||
import { WorkflowCronTrigger } from '@/workflow/types/Workflow';
|
||||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
|
||||
|
||||
const DEFAULT_CRON_PATTERN = '0 */1 * * *'; // Every hour
|
||||
|
||||
export const getCronTriggerDefaultSettings = (
|
||||
cronTriggerInterval: CronTriggerInterval,
|
||||
): WorkflowCronTrigger['settings'] => {
|
||||
switch (cronTriggerInterval) {
|
||||
case 'HOURS':
|
||||
return {
|
||||
schedule: {
|
||||
hour: 1,
|
||||
minute: 0,
|
||||
},
|
||||
type: cronTriggerInterval,
|
||||
outputSchema: {},
|
||||
};
|
||||
case 'MINUTES':
|
||||
return {
|
||||
schedule: {
|
||||
minute: 1,
|
||||
},
|
||||
type: cronTriggerInterval,
|
||||
outputSchema: {},
|
||||
};
|
||||
case 'CUSTOM':
|
||||
return {
|
||||
pattern: DEFAULT_CRON_PATTERN,
|
||||
type: cronTriggerInterval,
|
||||
outputSchema: {},
|
||||
};
|
||||
}
|
||||
return assertUnreachable(
|
||||
cronTriggerInterval,
|
||||
'Invalid cron trigger interval',
|
||||
);
|
||||
};
|
||||
@ -45,6 +45,16 @@ export const getTriggerDefaultDefinition = ({
|
||||
}),
|
||||
};
|
||||
}
|
||||
case 'CRON': {
|
||||
return {
|
||||
type,
|
||||
settings: {
|
||||
type: 'HOURS',
|
||||
schedule: { hour: 1, minute: 0 },
|
||||
outputSchema: {},
|
||||
},
|
||||
};
|
||||
}
|
||||
default: {
|
||||
return assertUnreachable(type, `Unknown type: ${type}`);
|
||||
}
|
||||
|
||||
@ -6,6 +6,9 @@ export const getTriggerIcon = (
|
||||
| {
|
||||
type: 'MANUAL';
|
||||
}
|
||||
| {
|
||||
type: 'CRON';
|
||||
}
|
||||
| {
|
||||
type: 'DATABASE_EVENT';
|
||||
eventName: string;
|
||||
|
||||
@ -6,6 +6,9 @@ export const getTriggerDefaultLabel = (
|
||||
| {
|
||||
type: 'MANUAL';
|
||||
}
|
||||
| {
|
||||
type: 'CRON';
|
||||
}
|
||||
| {
|
||||
type: 'DATABASE_EVENT';
|
||||
eventName: string;
|
||||
|
||||
Reference in New Issue
Block a user