Skip to content

Commit 3d082d6

Browse files
committed
feat(core): enhance scheduling functionality with output handling and email notifications
- Introduced new methods for appending output to files and sending email notifications based on task results. - Updated Schedule class to support shell command execution and improved error handling. - Refactored ScheduleOptions to include output file options for better flexibility. - Commented out previous scheduling commands in the sample app for clarity. - Removed unused imports in ScheduleServiceTest to streamline the code.
1 parent 010ac5e commit 3d082d6

File tree

4 files changed

+196
-73
lines changed

4 files changed

+196
-73
lines changed

integrations/sample-app/app/boot/sp/app.ts

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,46 @@ export class AppServiceProvider extends ServiceProvider {
4242
/**
4343
* Schedule Intent Command to run daily.
4444
*/
45-
Schedule.command('send:email')
46-
// .days([Schedule.MONDAY, Schedule.THURSDAY])
47-
.hourly()
48-
.timezone('America/Chicago')
49-
.between('8:00', '17:00')
45+
46+
Schedule.exec('ls -la')
47+
.everyTwoSeconds()
48+
.appendOutputToFile('output.txt')
49+
.emailOutputTo('vinayak@tryhanalabs.com')
5050
.run();
5151

52+
// Schedule.command('send:email')
53+
// // .days([Schedule.MONDAY, Schedule.THURSDAY])
54+
// .hourly()
55+
// .timezone('America/Chicago')
56+
// .between('8:00', '17:00')
57+
// .run();
58+
5259
/**
5360
* Simple callback, with lifecycle methods `before` and `after`.
5461
*/
55-
Schedule.call(() => {
56-
console.log('inside the schedule method');
57-
})
58-
.purpose('sample scheduler')
59-
.before(() => console.log('this will run before the cron'))
60-
.after((output: any) =>
61-
console.log('this will run after the cron', output),
62-
)
63-
.onSuccess((result) =>
64-
console.log('this will run on success the cron', result),
65-
)
66-
.onFailure((error) =>
67-
console.log('this will run on failure the cron', error),
68-
)
69-
// .pingBefore('https://webhook.site/79dcb789-869b-459d-9ba9-638aae449328')
70-
.thenPing('https://webhook.site/79dcb789-869b-459d-9ba9-638aae449328')
71-
.weekends()
72-
.everyTwoSeconds()
73-
.when(() => true)
74-
75-
.run();
62+
// Schedule.call(() => {
63+
// console.log('inside the schedule method');
64+
// return 'hello';
65+
// })
66+
// .purpose('sample scheduler')
67+
// .before(() => console.log('this will run before the cron'))
68+
// .after((output: any) =>
69+
// console.log('this will run after the cron', output),
70+
// )
71+
// .onSuccess((result) =>
72+
// console.log('this will run on success the cron', result),
73+
// )
74+
// .onFailure((error) =>
75+
// console.log('this will run on failure the cron', error),
76+
// )
77+
// // .pingBefore('https://webhook.site/79dcb789-869b-459d-9ba9-638aae449328')
78+
// .thenPing('https://webhook.site/79dcb789-869b-459d-9ba9-638aae449328')
79+
// .weekends()
80+
// .everyTwoSeconds()
81+
// // .pingOnSuccess('https://webhook.site/79dcb789-869b-459d-9ba9-638aae449328')
82+
// .when(() => true)
83+
// .appendOutputToFile('output.txt')
84+
// .run();
7685

7786
/**
7887
* Running a job every day at 5AM.
@@ -85,5 +94,15 @@ export class AppServiceProvider extends ServiceProvider {
8594
// .everyFiveSeconds()
8695
// .weekends()
8796
// .run();
97+
98+
// Schedule.command('emails:send')
99+
// .daily()
100+
// .onSuccess((result) => {
101+
// console.log('emails:send on success', result);
102+
// })
103+
// .onFailure((error: Error) => {
104+
// console.log('emails:send on failure', error);
105+
// })
106+
// .run();
88107
}
89108
}

integrations/sample-app/app/services/schedule.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
import { Injectable } from '@intentjs/core';
2-
import {
3-
Schedule,
4-
SchedulerRegistry,
5-
ScheduleRun,
6-
} from '@intentjs/core/schedule';
7-
82
@Injectable()
93
export class ScheduleServiceTest {
104
constructor() {}

packages/core/lib/scheduler/options/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type ScheduleOptions = {
44
name?: string;
55
timezone?: string;
66
purpose?: string;
7+
outputFile?: { file: string; append?: boolean };
78
};
89

910
export enum HandlerType {

0 commit comments

Comments
 (0)