@ -126,8 +126,12 @@ class SheetSync(object):
bustime = common . parse_bustime ( value )
bustime = common . parse_bustime ( value )
return common . bustime_to_dt ( self . bustime_start , bustime )
return common . bustime_to_dt ( self . bustime_start , bustime )
def wait ( self , interval ) :
def wait ( self , base , interval ) :
self . stop . wait ( common . jitter ( interval ) )
""" Wait until INTERVAL seconds after BASE. """
now = monotonic ( )
to_wait = base + common . jitter ( interval ) - now
if to_wait > 0 :
self . stop . wait ( to_wait )
def run ( self ) :
def run ( self ) :
self . conn = self . dbmanager . get_conn ( )
self . conn = self . dbmanager . get_conn ( )
@ -150,7 +154,10 @@ class SheetSync(object):
worksheets = sorted (
worksheets = sorted (
self . worksheets . keys ( ) , key = lambda k : self . worksheets [ k ] , reverse = True ,
self . worksheets . keys ( ) , key = lambda k : self . worksheets [ k ] , reverse = True ,
) [ : self . ACTIVE_SHEET_COUNT ]
) [ : self . ACTIVE_SHEET_COUNT ]
sync_count + = 1
sync_count + = 1
sync_start = monotonic ( )
for worksheet in worksheets :
for worksheet in worksheets :
rows = self . sheets . get_rows ( self . sheet_id , worksheet )
rows = self . sheets . get_rows ( self . sheet_id , worksheet )
for row_index , row in enumerate ( rows ) :
for row_index , row in enumerate ( rows ) :
@ -173,11 +180,11 @@ class SheetSync(object):
# If we can't re-connect, the program will crash from here,
# If we can't re-connect, the program will crash from here,
# then restart and wait until it can connect again.
# then restart and wait until it can connect again.
self . conn = self . dbmanager . get_conn ( )
self . conn = self . dbmanager . get_conn ( )
self . wait ( self . ERROR_RETRY_INTERVAL )
self . wait ( sync_start , self . ERROR_RETRY_INTERVAL )
else :
else :
logging . info ( " Successful sync " )
logging . info ( " Successful sync " )
sheets_synced . inc ( )
sheets_synced . inc ( )
self . wait ( self . RETRY_INTERVAL )
self . wait ( sync_start , self . RETRY_INTERVAL )
def get_events ( self ) :
def get_events ( self ) :
""" Return the entire events table as a map { id: event namedtuple} """
""" Return the entire events table as a map { id: event namedtuple} """