chore: rename Schedule integration as Scheduler
This commit is contained in:
40
packages/backend/src/apps/scheduler/triggers/every-day.ts
Normal file
40
packages/backend/src/apps/scheduler/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;
|
||||
}
|
||||
}
|
35
packages/backend/src/apps/scheduler/triggers/every-hour.ts
Normal file
35
packages/backend/src/apps/scheduler/triggers/every-hour.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { IJSONObject, IJSONValue, ITrigger } from '@automatisch/types';
|
||||
import { cronTimes, getNextCronDateTime, getDateTimeObjectRepresentation } from '../utils';
|
||||
|
||||
export default class EveryHour implements ITrigger {
|
||||
triggersOnWeekend?: boolean | string;
|
||||
|
||||
constructor(parameters: IJSONObject) {
|
||||
if (parameters.triggersOnWeekend) {
|
||||
this.triggersOnWeekend = parameters.triggersOnWeekend as string;
|
||||
}
|
||||
}
|
||||
|
||||
get interval() {
|
||||
if (this.triggersOnWeekend) {
|
||||
return cronTimes.everyHour;
|
||||
}
|
||||
|
||||
return cronTimes.everyHourExcludingWeekends;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
36
packages/backend/src/apps/scheduler/triggers/every-month.ts
Normal file
36
packages/backend/src/apps/scheduler/triggers/every-month.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { IJSONObject, IJSONValue, ITrigger } from '@automatisch/types';
|
||||
import { cronTimes, getNextCronDateTime, getDateTimeObjectRepresentation } from '../utils';
|
||||
|
||||
export default class EveryMonth implements ITrigger {
|
||||
day?: number;
|
||||
hour?: number;
|
||||
|
||||
constructor(parameters: IJSONObject) {
|
||||
if (parameters.day) {
|
||||
this.day = parameters.day as number;
|
||||
}
|
||||
|
||||
if (parameters.hour) {
|
||||
this.hour = parameters.hour as number;
|
||||
}
|
||||
}
|
||||
|
||||
get interval() {
|
||||
return cronTimes.everyMonthOnAndAt(this.day, 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;
|
||||
}
|
||||
}
|
36
packages/backend/src/apps/scheduler/triggers/every-week.ts
Normal file
36
packages/backend/src/apps/scheduler/triggers/every-week.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { IJSONObject, IJSONValue, ITrigger } from '@automatisch/types';
|
||||
import { cronTimes, getNextCronDateTime, getDateTimeObjectRepresentation } from '../utils';
|
||||
|
||||
export default class EveryWeek implements ITrigger {
|
||||
weekday?: number;
|
||||
hour?: number;
|
||||
|
||||
constructor(parameters: IJSONObject) {
|
||||
if (parameters.weekday) {
|
||||
this.weekday = parameters.weekday as number;
|
||||
}
|
||||
|
||||
if (parameters.hour) {
|
||||
this.hour = parameters.hour as number;
|
||||
}
|
||||
}
|
||||
|
||||
get interval() {
|
||||
return cronTimes.everyWeekOnAndAt(this.weekday, 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user