Merge pull request #322 from automatisch/new-every-day-trigger
feat: add every day trigger in schedule integration
This commit is contained in:
@@ -41,6 +41,148 @@
|
|||||||
"name": "Test trigger"
|
"name": "Test trigger"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Every day",
|
||||||
|
"key": "everyDay",
|
||||||
|
"description": "Triggers every day.",
|
||||||
|
"substeps": [
|
||||||
|
{
|
||||||
|
"key": "chooseTrigger",
|
||||||
|
"name": "Set up a trigger",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"label": "Trigger on weekends?",
|
||||||
|
"key": "triggersOnWeekend",
|
||||||
|
"type": "dropdown",
|
||||||
|
"description": "Should this flow trigger on Saturday and Sunday?",
|
||||||
|
"required": true,
|
||||||
|
"value": true,
|
||||||
|
"variables": false,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Yes",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "No",
|
||||||
|
"value": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Time of day",
|
||||||
|
"key": "hour",
|
||||||
|
"type": "dropdown",
|
||||||
|
"required": true,
|
||||||
|
"value": null,
|
||||||
|
"variables": false,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "00:00",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "01:00",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "02:00",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "03:00",
|
||||||
|
"value": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "04:00",
|
||||||
|
"value": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "05:00",
|
||||||
|
"value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "06:00",
|
||||||
|
"value": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "07:00",
|
||||||
|
"value": 7
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "08:00",
|
||||||
|
"value": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "09:00",
|
||||||
|
"value": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "10:00",
|
||||||
|
"value": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "11:00",
|
||||||
|
"value": 11
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "12:00",
|
||||||
|
"value": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "13:00",
|
||||||
|
"value": 13
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "14:00",
|
||||||
|
"value": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "15:00",
|
||||||
|
"value": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "16:00",
|
||||||
|
"value": 16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "17:00",
|
||||||
|
"value": 17
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "18:00",
|
||||||
|
"value": 18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "19:00",
|
||||||
|
"value": 19
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "20:00",
|
||||||
|
"value": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "21:00",
|
||||||
|
"value": 21
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "22:00",
|
||||||
|
"value": 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "23:00",
|
||||||
|
"value": 23
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "testStep",
|
||||||
|
"name": "Test trigger"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
import { IJSONObject } from '@automatisch/types';
|
||||||
import EveryHour from './triggers/every-hour';
|
import EveryHour from './triggers/every-hour';
|
||||||
|
import EveryDay from './triggers/every-day';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
everyHour: EveryHour;
|
everyHour: EveryHour;
|
||||||
|
everyDay: EveryDay;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.everyHour = new EveryHour(parameters);
|
this.everyHour = new EveryHour(parameters);
|
||||||
|
this.everyDay = new EveryDay(parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
packages/backend/src/apps/schedule/triggers/every-day.ts
Normal file
40
packages/backend/src/apps/schedule/triggers/every-day.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { DateTime } from 'luxon';
|
||||||
|
import type { IJSONObject, IJSONValue, ITrigger } from '@automatisch/types';
|
||||||
|
import { cronTimes, getNextCronDateTime, getDateTimeObjectRepresentation } from '../utils';
|
||||||
|
|
||||||
|
export default class EveryDay implements ITrigger {
|
||||||
|
triggersOnWeekend?: boolean;
|
||||||
|
hour?: number;
|
||||||
|
|
||||||
|
constructor(parameters: IJSONObject) {
|
||||||
|
if (parameters.triggersOnWeekend) {
|
||||||
|
this.triggersOnWeekend = parameters.triggersOnWeekend as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameters.hour) {
|
||||||
|
this.hour = parameters.hour as number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get interval() {
|
||||||
|
if (this.triggersOnWeekend) {
|
||||||
|
return cronTimes.everyDayAt(this.hour);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cronTimes.everyDayExcludingWeekendsAt(this.hour);
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(startDateTime: Date) {
|
||||||
|
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||||
|
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||||
|
|
||||||
|
return [dateTimeObjectRepresentation] as IJSONValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
async testRun() {
|
||||||
|
const nextCronDateTime = getNextCronDateTime(this.interval);
|
||||||
|
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||||
|
|
||||||
|
return [dateTimeObjectRepresentation] as IJSONValue;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,8 @@ import cronParser from 'cron-parser';
|
|||||||
export const cronTimes = {
|
export const cronTimes = {
|
||||||
everyHour: '0 * * * *',
|
everyHour: '0 * * * *',
|
||||||
everyHourExcludingWeekends: '0 * * * 1-5',
|
everyHourExcludingWeekends: '0 * * * 1-5',
|
||||||
|
everyDayAt: (hour: number) => `0 ${hour} * * *`,
|
||||||
|
everyDayExcludingWeekendsAt: (hour: number) => `0 ${hour} * * 1-5`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getNextCronDateTime(cronString: string) {
|
export function getNextCronDateTime(cronString: string) {
|
||||||
|
@@ -51,7 +51,7 @@ export default function InputCreator(props: InputCreatorProps): React.ReactEleme
|
|||||||
const computedName = namePrefix ? `${namePrefix}.${name}` : name;
|
const computedName = namePrefix ? `${namePrefix}.${name}` : name;
|
||||||
|
|
||||||
if (type === 'dropdown') {
|
if (type === 'dropdown') {
|
||||||
const preparedOptions = schema.options || optionGenerator(data?.getData);
|
const preparedOptions = schema.options || optionGenerator(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ControlledAutocomplete
|
<ControlledAutocomplete
|
||||||
|
Reference in New Issue
Block a user