import schedule from 'node-schedule'; import { remote } from '../proto/runtime/v1alpha1/remote'; import { SymbolTable, JetroutineFunction } from '../config/_symbols'; import { defaultJetpackClient } from './client'; import { Jetroutine } from './jetroutine'; // scheduleRule accepts kubernete-like syntax of "* * * * *" // function in func field should not have any arguments export function cron(uniqueName: string, scheduleRule: string, func: JetroutineFunction) { const cronjob = new remote.CronJob({ qualified_symbol: uniqueName, schedule_rule: scheduleRule, }); SymbolTable.registerCron(uniqueName, cronjob); schedule.scheduleJob(scheduleRule, async () => { await func(); }); return new Jetroutine({ uniqueName, func, runtimeClient: defaultJetpackClient._getRuntimeClient(), }); }