@@ -74,20 +74,19 @@ export const holdWhileWanted = <E, R>(
7474 Stream . runDrain ,
7575 ) ;
7676
77- // Reads and the inhibitor retry until they succeed; the cap keeps a host without an
78- // inhibitor (e.g. no logind) from retrying and warning constantly.
77+ // Reads, the event subscription and the inhibitor retry until they succeed; the cap keeps a
78+ // host without an inhibitor (e.g. no logind) from retrying and warning constantly.
79+ const backoff = Schedule . exponential ( "5 seconds" ) . pipe (
80+ Schedule . modifyDelay ( ( { duration } ) =>
81+ Effect . succeed ( Duration . min ( duration , Duration . minutes ( 10 ) ) ) ,
82+ ) ,
83+ ) ;
7984const retryWithBackoff =
8085 ( message : string ) =>
8186 < A , E , R > ( effect : Effect . Effect < A , E , R > ) =>
8287 effect . pipe (
8388 Effect . tapCause ( ( cause ) => Effect . logWarning ( message , { cause } ) ) ,
84- Effect . retry (
85- Schedule . exponential ( "5 seconds" ) . pipe (
86- Schedule . modifyDelay ( ( { duration } ) =>
87- Effect . succeed ( Duration . min ( duration , Duration . minutes ( 10 ) ) ) ,
88- ) ,
89- ) ,
90- ) ,
89+ Effect . retry ( backoff ) ,
9190 ) ;
9291
9392class KeepAwakeInhibitorExited extends Schema . TaggedError < KeepAwakeInhibitorExited > ( ) (
@@ -132,7 +131,14 @@ export const layer = Layer.effectDiscard(
132131 ) ,
133132 ) ,
134133 ) ,
135- ) . pipe ( Stream . mapEffect ( ( ) => hasActiveRun ) ) ;
134+ ) . pipe (
135+ Stream . mapEffect ( ( ) => hasActiveRun ) ,
136+ // A failed subscription resubscribes, which re-reads the cursor and the snapshot.
137+ Stream . tapCause ( ( cause ) =>
138+ Effect . logWarning ( "keep-awake run event stream failed" , { cause } ) ,
139+ ) ,
140+ Stream . retry ( backoff ) ,
141+ ) ;
136142 const enabled = Stream . unwrap (
137143 Effect . gen ( function * ( ) {
138144 const changes = yield * settings . subscribeChanges ;
0 commit comments