def _schedule_reidentify(self, identify_response, immediate=False): # self.disconnect() clears self.connection to None if self.connection is None: _log.warning('_schedule_reidentify: self.connection is None, skipping') return # cancel previous timer self._cancel_reidentify_timer() # non-primary connection, do not reschedule if not self.connection.is_primary(): _log.debug('non-primary connection, no reidentify') return # compute time difference to recheck now = datetime.datetime.utcnow() try: recheck = identify_response['licenseRecheckLatestAt'] except: _log.exception('failed to get licenseRecheckLatestAt, using current time as fallback') recheck = now diff = recheck - now # cap it: minimum and maximum (also takes care of negative bogus diffs) cap_diff = diff if cap_diff < constants.MANAGEMENT_PROTOCOL_REIDENTIFY_MINIMUM_TIME: cap_diff = constants.MANAGEMENT_PROTOCOL_REIDENTIFY_MINIMUM_TIME if cap_diff > constants.MANAGEMENT_PROTOCOL_REIDENTIFY_MAXIMUM_TIME: cap_diff = constants.MANAGEMENT_PROTOCOL_REIDENTIFY_MAXIMUM_TIME if immediate: cap_diff = datetime.timedelta(0, 0, 0) _log.debug('reidentify diff before capping: %s, after capping and immediate flag check: %s' % (diff, cap_diff)) # start a timer secs = helpers.timedelta_to_seconds(cap_diff) self._reidentify_call = reactor.callLater(secs, self._reidentify_timer)
def _timeticks(td): return int(helpers.timedelta_to_seconds(td) * 100.0)