File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -179,8 +179,8 @@ export const uptimeRouter = {
179179 ) ;
180180
181181 const scheduleId = input . websiteId || nanoid ( 10 ) ;
182- await createQStashSchedule ( scheduleId , input . granularity ) ;
183182
183+ // Insert to DB first
184184 await db . insert ( uptimeSchedules ) . values ( {
185185 id : scheduleId ,
186186 websiteId : input . websiteId ?? null ,
@@ -192,6 +192,18 @@ export const uptimeRouter = {
192192 isPaused : false ,
193193 } ) ;
194194
195+ // Then create QStash schedule, rollback DB if it fails
196+ try {
197+ await createQStashSchedule ( scheduleId , input . granularity ) ;
198+ } catch ( error ) {
199+ await db . delete ( uptimeSchedules ) . where ( eq ( uptimeSchedules . id , scheduleId ) ) ;
200+ logger . error ( { scheduleId, error } , "QStash creation failed, rolled back" ) ;
201+ throw new ORPCError ( "INTERNAL_SERVER_ERROR" , {
202+ message : "Failed to create monitor" ,
203+ } ) ;
204+ }
205+
206+ // Trigger initial check (fire-and-forget)
195207 client
196208 . publish ( {
197209 urlGroup : UPTIME_URL_GROUP ,
You can’t perform that action at this time.
0 commit comments