Skip to content

Commit bb7fb04

Browse files
authored
Adds additional scheduler methods (#55)
* fix: export and existing method names * feat: additional SchedulerClient methods and test
1 parent fa3a000 commit bb7fb04

File tree

3 files changed

+86
-19
lines changed

3 files changed

+86
-19
lines changed

src/core/__test__/schedulerExecutor.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ describe("ScheduleExecutor", () => {
6767
},
6868
};
6969
await expect(
70-
executor.registerSchedule(schedulerDefinition)
70+
executor.saveSchedule(schedulerDefinition)
7171
).resolves.not.toThrowError();
72-
const scheduler = await executor.get(name);
72+
const scheduler = await executor.getSchedule(name);
7373
expect(scheduler.name).toEqual(name);
7474
expect(scheduler.cronExpression).toEqual(cronExpression);
7575
});
7676

7777
test("Should be able to resume the schedule", async () => {
7878
const client = await clientPromise;
7979
const executor = new SchedulerClient(client);
80-
await executor.startResume(name);
81-
const scheduler = await executor.get(name);
80+
await executor.resumeSchedule(name);
81+
const scheduler = await executor.getSchedule(name);
8282
expect(scheduler.paused).toBeFalsy();
8383
});
8484

@@ -99,24 +99,32 @@ describe("ScheduleExecutor", () => {
9999
test("Should be able to pause the schedule", async () => {
100100
const client = await clientPromise;
101101
const executor = new SchedulerClient(client);
102-
await executor.pause(name);
103-
const scheduler = await executor.get(name);
102+
await executor.pauseSchedule(name);
103+
const scheduler = await executor.getSchedule(name);
104104
expect(scheduler.paused).toBeTruthy();
105105
});
106106

107107
test("Should be able to delete the schedule", async () => {
108108
const client = await clientPromise;
109109
const executor = new SchedulerClient(client);
110-
await executor.delete(name);
110+
await executor.deleteSchedule(name);
111111
// delete workflowDef too
112112
await client.metadataResource.unregisterWorkflowDef(
113113
workflowName,
114114
workflowVersion
115115
);
116-
const schedulerList = await executor.getAll();
116+
const schedulerList = await executor.getAllSchedules();
117117
const testSchedule = schedulerList.some(
118118
(schedule) => schedule.name === name
119119
);
120120
expect(testSchedule).toBeFalsy();
121121
});
122+
123+
test("Should be able to retrieve next (default 3) execution times for a scheduler", async () => {
124+
const cronExpression = "0 0 * ? * *"; //every hour
125+
const client = await clientPromise;
126+
const executor = new SchedulerClient(client);
127+
const result = await executor.getNextFewSchedules(cronExpression);
128+
expect(result?.length).toBeGreaterThan(0);
129+
});
122130
});

src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./types";
33
export * from "./human";
44
export * from "./sdk";
55
export * from "./generators";
6+
export * from "./schedulerClient";

src/core/schedulerClient.ts

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SchedulerClient {
1818
* @param requestBody
1919
* @returns
2020
*/
21-
public registerSchedule(param: SaveScheduleRequest): Promise<void> {
21+
public saveSchedule(param: SaveScheduleRequest): Promise<void> {
2222
return tryCatchReThrow(() =>
2323
this._client.schedulerResource.saveSchedule(param)
2424
);
@@ -57,7 +57,7 @@ export class SchedulerClient {
5757
* @param name
5858
* @returns SaveScheduleRequest
5959
*/
60-
public get(name: string): Promise<SaveScheduleRequest> {
60+
public getSchedule(name: string): Promise<SaveScheduleRequest> {
6161
return tryCatchReThrow(() =>
6262
this._client.schedulerResource.getSchedule(name)
6363
);
@@ -68,7 +68,7 @@ export class SchedulerClient {
6868
* @param name
6969
* @returns
7070
*/
71-
public pause(name: string): Promise<void> {
71+
public pauseSchedule(name: string): Promise<void> {
7272
return tryCatchReThrow(() =>
7373
this._client.schedulerResource.pauseSchedule(name)
7474
);
@@ -80,7 +80,7 @@ export class SchedulerClient {
8080
* @param name
8181
* @returns
8282
*/
83-
public startResume(name: string): Promise<void> {
83+
public resumeSchedule(name: string): Promise<void> {
8484
return tryCatchReThrow(() =>
8585
this._client.schedulerResource.resumeSchedule(name)
8686
);
@@ -92,22 +92,80 @@ export class SchedulerClient {
9292
* @param name
9393
* @returns
9494
*/
95-
public delete(name: string): Promise<void> {
95+
public deleteSchedule(name: string): Promise<void> {
9696
return tryCatchReThrow(() =>
9797
this._client.schedulerResource.deleteSchedule(name)
9898
);
9999
}
100100

101-
102101
/**
103-
* Get all existing workflow schedules and optionally filter by workflow name
102+
* Get all existing workflow schedules and optionally filter by workflow name
104103
* @param workflowName
105104
* @returns Array<WorkflowSchedule>
106105
*/
107-
public getAll(workflowName?: string):Promise<Array<WorkflowSchedule>>{
108-
return tryCatchReThrow(()=>
109-
this._client.schedulerResource.getAllSchedules(workflowName)
110-
)
106+
public getAllSchedules(
107+
workflowName?: string
108+
): Promise<Array<WorkflowSchedule>> {
109+
return tryCatchReThrow(() =>
110+
this._client.schedulerResource.getAllSchedules(workflowName)
111+
);
112+
}
113+
114+
/**
115+
* Get list of the next x (default 3, max 5) execution times for a scheduler
116+
* @param cronExpression
117+
* @param scheduleStartTime
118+
* @param scheduleEndTime
119+
* @param limit
120+
* @returns number OK
121+
* @throws ApiError
122+
*/
123+
public getNextFewSchedules(
124+
cronExpression: string,
125+
scheduleStartTime?: number,
126+
scheduleEndTime?: number,
127+
limit: number = 3
128+
): Promise<Array<number[]>> {
129+
return tryCatchReThrow(() =>
130+
this._client.schedulerResource.getNextFewSchedules(
131+
cronExpression,
132+
scheduleStartTime,
133+
scheduleEndTime,
134+
limit
135+
)
136+
);
111137
}
112138

139+
/**
140+
* Pause all scheduling in a single conductor server instance (for debugging only)
141+
* @returns any OK
142+
* @throws ApiError
143+
*/
144+
public pauseAllSchedules(): Promise<void> {
145+
return tryCatchReThrow(() =>
146+
this._client.schedulerResource.pauseAllSchedules()
147+
);
148+
}
149+
150+
/**
151+
* Requeue all execution records
152+
* @returns any OK
153+
* @throws ApiError
154+
*/
155+
public requeueAllExecutionRecords(): Promise<void> {
156+
return tryCatchReThrow(() =>
157+
this._client.schedulerResource.requeueAllExecutionRecords()
158+
);
159+
}
160+
161+
/**
162+
* Resume all scheduling
163+
* @returns any OK
164+
* @throws ApiError
165+
*/
166+
public resumeAllSchedules(): Promise<void> {
167+
return tryCatchReThrow(() =>
168+
this._client.schedulerResource.resumeAllSchedules()
169+
);
170+
}
113171
}

0 commit comments

Comments
 (0)