@@ -149,4 +149,113 @@ export class WebhookResponse {
149149 static fromJson ( json : any ) : WebhookResponse {
150150 return new WebhookResponse ( json . id , json . status , new Date ( json . created_at ) , json . updated_at ? new Date ( json . updated_at ) : null , json . error ) ;
151151 }
152+ }
153+
154+ export type ScheduleJobType = 'cron' | 'interval' ;
155+
156+ // This cron expression is with seconds (e.g. '*/5 * * * * *' for every 5 seconds)
157+ export const CronExpression = {
158+ Every5Seconds : '*/5 * * * * *' ,
159+ Every10Seconds : '*/10 * * * * *' ,
160+ Every30Seconds : '*/30 * * * * *' ,
161+ Every1Minute : '0 * * * * *' ,
162+ Every5Minutes : '*/5 * * * * *' ,
163+ Every10Minutes : '*/10 * * * * *' ,
164+ Every30Minutes : '*/30 * * * * *' ,
165+ Every1Hour : '0 0 * * * *' ,
166+ Every6Hours : '0 0 */6 * * *' ,
167+ Every12Hours : '0 0 */12 * * *' ,
168+ }
169+
170+ export class ScheduleJob {
171+ webhook_url : string ;
172+ webhook_data : any ;
173+ type : ScheduleJobType ;
174+ // cron e.g. '*/5 * * * * *' for every 5 seconds or '0 0 12 * * *' for every day at 12:00 PM
175+ // interval e.g. '5s' for every 5 seconds or '1h' for every 1 hour (unit: s, m, h, d, w)
176+ schedule : string ;
177+ tz ?: string ;
178+
179+ constructor ( webhook_url : string , webhook_data : any , type : ScheduleJobType , schedule : string , tz ?: string ) {
180+ this . webhook_url = webhook_url ;
181+ this . webhook_data = webhook_data ;
182+ this . type = type ;
183+ this . schedule = schedule ;
184+ this . tz = tz ;
185+ }
186+
187+ static builder ( ) : ScheduleJobBuilder {
188+ return new ScheduleJobBuilder ( ) ;
189+ }
190+ }
191+
192+ class ScheduleJobBuilder {
193+ private _webhook_url : string ;
194+ private _webhook_data : any ;
195+ private _type : ScheduleJobType ;
196+ private _schedule : string ;
197+ private _tz ?: string ;
198+
199+ constructor ( ) {
200+ this . _webhook_url = '' ;
201+ this . _webhook_data = undefined ;
202+ this . _type = 'cron' ;
203+ this . _schedule = '' ;
204+ this . _tz = undefined ;
205+ }
206+
207+ webhook_url ( webhook_url : string ) : ScheduleJobBuilder {
208+ this . _webhook_url = webhook_url ;
209+ return this ;
210+ }
211+
212+ webhook_data ( webhook_data : any ) : ScheduleJobBuilder {
213+ this . _webhook_data = webhook_data ;
214+ return this ;
215+ }
216+
217+ type ( type : ScheduleJobType ) : ScheduleJobBuilder {
218+ this . _type = type ;
219+ return this ;
220+ }
221+
222+ schedule ( schedule : string ) : ScheduleJobBuilder {
223+ this . _schedule = schedule ;
224+ return this ;
225+ }
226+
227+ tz ( tz : string ) : ScheduleJobBuilder {
228+ this . _tz = tz ;
229+ return this ;
230+ }
231+
232+ build ( ) : ScheduleJob {
233+ return new ScheduleJob ( this . _webhook_url , this . _webhook_data , this . _type , this . _schedule , this . _tz ) ;
234+ }
235+ }
236+
237+ export class ScheduleJobResponse {
238+ key : string ;
239+ job_id : string ;
240+ job_status : number ; // 100: not started, 200: scheduled, 300: running, 400: failed, 500: terminated, 600: completed
241+ type : ScheduleJobType ;
242+ next_run ?: Date ;
243+ last_run ?: Date ;
244+ created_at ?: Date ;
245+ updated_at ?: Date ;
246+
247+ constructor ( key : string , job_id : string , job_status : number , type : ScheduleJobType , next_run ?: Date , last_run ?: Date , created_at ?: Date , updated_at ?: Date ) {
248+ this . key = key ;
249+ this . job_id = job_id ;
250+ this . job_status = job_status ;
251+ this . type = type ;
252+ this . next_run = next_run ;
253+ this . last_run = last_run ;
254+ this . created_at = created_at ;
255+ this . updated_at = updated_at ;
256+ }
257+
258+ static fromJson ( json : any ) : ScheduleJobResponse {
259+ return new ScheduleJobResponse ( json . key , json . job_id , json . job_status , json . type , json . next_run ? new Date ( json . next_run ) : undefined , json . last_run ? new Date ( json . last_run ) : undefined , new Date ( json . created_at ) , json . updated_at ? new Date ( json . updated_at ) : undefined ) ;
260+ }
152261}
0 commit comments