@@ -28,6 +28,7 @@ import * as $ from 'jquery';
2828const SVG_NAMESPACE = 'http://www.w3.org/2000/svg' ;
2929
3030const SECOND_HAND_ANIMATION_TIME = 200 ;
31+ const MAX_RANDOM_LEAP_SECOND_POLL_DELAY = 120000 ; // Two minutes
3132const LEAP_SECOND_RETRY_DELAY = 300000 ; // 5 minutes
3233
3334const MILLIS_PER_DAY = 86400000 ;
@@ -63,6 +64,7 @@ export class Clock {
6364 private lastTick = - 1 ;
6465 private inMinuteOfLeapSecond = false ;
6566 private pendingLeapSecondForMonth = 0 ;
67+ private firstLeapSecondPoll = true ;
6668 private lastLeapSecondCheckDay = - 1 ;
6769 private upcomingLeapSecond : CurrentDelta ;
6870
@@ -349,15 +351,20 @@ export class Clock {
349351 }
350352
351353 private getLeapSecondInfo ( ) : void {
352- // noinspection JSIgnoredPromiseFromCall
353- $ . ajax ( {
354- url : this . appService . getWeatherServer ( ) + '/tai-utc' ,
355- dataType : 'json' ,
356- success : ( data : CurrentDelta ) => this . upcomingLeapSecond = data ,
357- error : ( ) => setTimeout ( ( ) => {
358- this . upcomingLeapSecond = undefined ;
359- this . lastLeapSecondCheckDay = - 1 ;
360- } , LEAP_SECOND_RETRY_DELAY )
361- } ) ;
354+ setTimeout ( ( ) => {
355+ this . firstLeapSecondPoll = false ;
356+
357+ // noinspection JSIgnoredPromiseFromCall
358+ $ . ajax ( {
359+ url : this . appService . getWeatherServer ( ) + '/tai-utc' ,
360+ dataType : 'json' ,
361+ success : ( data : CurrentDelta ) => this . upcomingLeapSecond = data ,
362+ error : ( ) => setTimeout ( ( ) => {
363+ this . upcomingLeapSecond = undefined ;
364+ this . lastLeapSecondCheckDay = - 1 ;
365+ } , LEAP_SECOND_RETRY_DELAY )
366+ } ) ;
367+ // Randomly delay polling so that multiple clock instances don't all poll at the same time every day.
368+ } , this . firstLeapSecondPoll ? 0 : Math . floor ( Math . random ( ) * MAX_RANDOM_LEAP_SECOND_POLL_DELAY ) ) ;
362369 }
363370}
0 commit comments