@@ -123,8 +123,10 @@ async function runHeartbeat(env) {
123123 if ( ! state . historyByService ) state . historyByService = { } ;
124124
125125 let statusChanged = false ;
126+ let needsSave = false ;
126127 let notifications = [ ] ;
127128 const heartbeatAt = Date . now ( ) ;
129+ const todayUTC = new Date ( heartbeatAt ) . toISOString ( ) . slice ( 0 , 10 ) ; // "YYYY-MM-DD"
128130
129131 for ( const target of targets ) {
130132 if ( state . services [ target . id ] ?. isManual ) {
@@ -168,25 +170,46 @@ async function runHeartbeat(env) {
168170 status : newStatus ,
169171 latency : latency
170172 } ) ;
173+
174+ // Internal log every heartbeat (no KV write)
175+ console . log ( `[heartbeat] ${ target . name } : ${ newStatus } ${ latency !== null ? ` (${ latency } ms)` : '' } ` ) ;
171176 }
172177
173- // Fetch maintained issues from ProjectHub
174- try {
175- const issuesRes = await fetch ( 'https://api.github.com/repos/SillyLittleTech/projecthub/issues?labels=maintain&state=open' , {
176- headers : {
177- 'User-Agent' : 'SLT-Status-Worker' ,
178- 'Authorization' : env . ISSUES_PAT ? `Bearer ${ env . ISSUES_PAT } ` : ''
178+ // Fetch maintained issues from ProjectHub at most once per day
179+ const lastIssuesFetchDate = state . _lastIssuesFetchDay || '' ;
180+ if ( lastIssuesFetchDate !== todayUTC ) {
181+ try {
182+ const issuesRes = await fetch ( 'https://api.github.com/repos/SillyLittleTech/projecthub/issues?labels=maintain&state=open' , {
183+ headers : {
184+ 'User-Agent' : 'SLT-Status-Worker' ,
185+ 'Authorization' : env . ISSUES_PAT ? `Bearer ${ env . ISSUES_PAT } ` : ''
186+ }
187+ } ) ;
188+ if ( issuesRes . ok ) {
189+ const issues = await issuesRes . json ( ) ;
190+ state . maintenance = issues . map ( i => ( { title : i . title , url : i . html_url , created_at : i . created_at } ) ) ;
191+ state . _lastIssuesFetchDay = todayUTC ;
192+ console . log ( `[daily] Fetched ${ issues . length } maintenance issue(s) for ${ todayUTC } ` ) ;
193+ needsSave = true ; // persist updated maintenance list
179194 }
180- } ) ;
181- if ( issuesRes . ok ) {
182- const issues = await issuesRes . json ( ) ;
183- state . maintenance = issues . map ( i => ( { title : i . title , url : i . html_url , created_at : i . created_at } ) ) ;
195+ } catch ( e ) {
196+ console . error ( 'Failed to fetch maintenance issues' , e ) ;
184197 }
185- } catch ( e ) {
186- console . error ( 'Failed to fetch maintenance issues' , e ) ;
187198 }
188199
189- await saveState ( env , state ) ;
200+ // Only write to KV when something changed, or once per day as a daily summary
201+ const lastDailySaveDate = state . _lastDailySaveDay || '' ;
202+ const isDailySave = lastDailySaveDate !== todayUTC ;
203+ if ( statusChanged || needsSave || isDailySave ) {
204+ if ( isDailySave ) {
205+ state . _lastDailySaveDay = todayUTC ;
206+ const summary = Object . entries ( state . services )
207+ . map ( ( [ , svc ] ) => `${ svc . name } : ${ svc . status } ` )
208+ . join ( ', ' ) ;
209+ console . log ( `[daily summary] ${ todayUTC } — ${ summary } ` ) ;
210+ }
211+ await saveState ( env , state ) ;
212+ }
190213}
191214
192215async function saveState ( env , state ) {
0 commit comments