Skip to content

Commit 4053c8a

Browse files
authored
fix: don't update schedule if frequency is alread set to the same value (NangoHQ#2380)
We were always updating the frequency even when we didn't need to. This doesn't address the log saying frequency has been updated. I will do that later ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] I added observability, otherwise the reason is: - [ ] I added analytics, otherwise the reason is:
1 parent e3075fc commit 4053c8a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/scheduler/lib/scheduler.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,17 @@ export class Scheduler {
383383
*/
384384
public async setScheduleFrequency({ scheduleName, frequencyMs }: { scheduleName: string; frequencyMs: number }): Promise<Result<Schedule>> {
385385
return this.dbClient.db.transaction(async (trx) => {
386-
const schedule = await schedules.search(trx, { names: [scheduleName], limit: 1, forUpdate: true });
386+
const schedule = await schedules.search(trx, { names: [scheduleName], limit: 1 });
387387
if (schedule.isErr()) {
388388
return Err(schedule.error);
389389
}
390390
if (!schedule.value[0]) {
391391
return Err(`Schedule '${scheduleName}' not found`);
392392
}
393+
// No-op if the schedule is already in the desired frequency
394+
if (schedule.value[0].frequencyMs === frequencyMs) {
395+
return Ok(schedule.value[0]);
396+
}
393397
const res = await schedules.update(trx, { id: schedule.value[0].id, frequencyMs });
394398
if (res.isErr()) {
395399
return Err(`Error updating schedule frequency '${scheduleName}': ${stringifyError(res.error)}`);

packages/shared/lib/services/sync/manager.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class SyncManagerService {
131131
}
132132

133133
const createdSync = await createSync(connection.id as number, syncName);
134-
orchestrator.scheduleSyncHelper(
134+
await orchestrator.scheduleSyncHelper(
135135
connection,
136136
createdSync as Sync,
137137
syncConfig as ProviderConfig,

0 commit comments

Comments
 (0)