@@ -29,6 +29,16 @@ export class RateWorkerOptions {
2929 }
3030}
3131
32+ export class CronWorkerOptions {
33+ public readonly description : string ;
34+ public readonly cron : string ;
35+
36+ constructor ( description : string , cron : string ) {
37+ this . description = description ;
38+ this . cron = cron ;
39+ }
40+ }
41+
3242/**
3343 * Provides a rate based schedule
3444 *
@@ -65,6 +75,26 @@ class Rate {
6575 }
6676}
6777
78+ /**
79+ * Provides a cron based schedule
80+ */
81+ class Cron {
82+ public readonly schedule : Schedule ;
83+ private readonly faas : Faas ;
84+
85+ constructor ( schedule : Schedule , cron : string , ...mw : EventMiddleware [ ] ) {
86+ this . schedule = schedule ;
87+ this . faas = new Faas (
88+ new CronWorkerOptions ( schedule [ 'description' ] , cron )
89+ ) ;
90+ this . faas . event ( ...mw ) ;
91+ }
92+
93+ private async start ( ) : Promise < void > {
94+ return this . faas . start ( ) ;
95+ }
96+ }
97+
6898/**
6999 * Providers a scheduled worker.
70100 */
@@ -92,6 +122,12 @@ class Schedule {
92122 // Start the new rate immediately
93123 return r [ 'start' ] ( ) ;
94124 }
125+
126+ cron = ( expression : string , ...mw : EventMiddleware [ ] ) : Promise < void > => {
127+ const r = new Cron ( this , expression , ...mw ) ;
128+ // Start the new cron immediately
129+ return r [ 'start' ] ( ) ;
130+ }
95131}
96132
97133/**
0 commit comments