Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/webapp/app/v3/services/createBackgroundWorker.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,43 @@ describe("syncDeclarativeSchedules registration", () => {
}
);

containerTest(
"preserves an existing Redis job when task schedule omits explicit UTC timezone",
async ({ prisma, redisOptions }) => {
const { project, prodEnv } = await seedProjectWithEnvs(prisma);
const schedule = await makeDeclarativeSchedule(prisma, project.id, [prodEnv.id]);
const updatedAt = schedule.updatedAt;
await seedScheduledTask(prisma, project.id, prodEnv.id);
const engine = createTestScheduleEngine(prisma, redisOptions);

try {
const jobId = scheduleJobId(schedule.instances[0].id);
await engine.registerNextTaskScheduleInstance({ instanceId: schedule.instances[0].id });
const before = await engine.getJob(jobId);

// Omit explicit timezone to verify default UTC normalization does not trigger false timing change
await syncDeclarativeSchedules(
declarativeTasks({ cron: "0 * * * *" }),
noWorker,
asEnv(prodEnv),
prisma,
engine
);

expect(before).toBeDefined();
expect(await engine.getJob(jobId)).toEqual(before);
expect(
await prisma.taskSchedule.findUniqueOrThrow({
where: { id: schedule.id },
select: { updatedAt: true },
})
).toEqual({ updatedAt });
} finally {
await engine.quit();
}
}
);

containerTest(
"replaces the Redis job when declarative timing changes",
async ({ prisma, redisOptions }) => {
Expand Down
13 changes: 8 additions & 5 deletions apps/webapp/app/v3/services/createBackgroundWorker.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ export async function syncDeclarativeSchedules(
environment.projectId,
{
cron: task.schedule.cron,
timezone: task.schedule.timezone,
timezone: task.schedule.timezone ?? "UTC",
taskIdentifier: task.id,
friendlyId: existingSchedule?.friendlyId,
window: task.schedule.window,
Expand Down Expand Up @@ -1623,15 +1623,18 @@ export async function syncDeclarativeSchedules(
windowPercentage: normalizedWindow.windowPercentage,
defaultWindowDurationSeconds: existingSchedule.defaultWindowDurationSeconds,
}).window;
const taskTimezone = task.schedule.timezone ?? "UTC";
const existingTimezone = existingSchedule.timezone ?? "UTC";
const timezoneChanged = existingTimezone !== taskTimezone;
const timingChanged =
existingSchedule.generatorExpression !== task.schedule.cron ||
existingSchedule.timezone !== task.schedule.timezone ||
timezoneChanged ||
!scheduleWindowsEqual(previousWindow, nextWindow) ||
// Clearing the minimum changes the effective range.
existingSchedule.minimumWindowDurationSeconds !== minimumWindowDurationSeconds;
const persistedValuesChanged =
existingSchedule.generatorExpression !== task.schedule.cron ||
existingSchedule.timezone !== task.schedule.timezone ||
timezoneChanged ||
existingSchedule.windowDurationSeconds !== normalizedWindow.windowDurationSeconds ||
existingSchedule.windowPercentage !== normalizedWindow.windowPercentage ||
existingSchedule.minimumWindowDurationSeconds !== minimumWindowDurationSeconds;
Expand All @@ -1643,7 +1646,7 @@ export async function syncDeclarativeSchedules(
data: {
generatorExpression: task.schedule.cron,
generatorDescription: cronstrue.toString(task.schedule.cron),
timezone: task.schedule.timezone,
timezone: taskTimezone,
minimumWindowDurationSeconds,
...normalizedWindow,
},
Expand Down Expand Up @@ -1675,7 +1678,7 @@ export async function syncDeclarativeSchedules(
taskIdentifier: task.id,
generatorExpression: task.schedule.cron,
generatorDescription: cronstrue.toString(task.schedule.cron),
timezone: task.schedule.timezone,
timezone: task.schedule.timezone ?? "UTC",
type: "DECLARATIVE",
minimumWindowDurationSeconds,
...normalizedWindow,
Expand Down