- self._state_to_set = state
- else:
- # always have a local variable because of parallelism
- state = self._state_to_set
-
- if not self._set_state_lock.acquire(False):
- # we don't want many threads to wait here
- # the next status update will fix everything anyways
- pass
- else:
- # got the lock
- try:
- # check if there's something we need to do
- if self._state_last_set == state: return
- # take action!
- success = self._do_request(state)
- # TODO error too often -> log critical to send mails
- if success:
- self._state_last_set = state
- finally:
- self._set_state_lock.release()
+ self._local_state = state
+ # check if there's something we need to do: There's a valid state, and either the state has changed or
+ # we need to refresh our heartbeta)
+ now = time.time()
+ if self._local_state is not None and (self._local_state != self._remote_state or now > self._last_set_at+HEARTBEAT_TIME):
+ # take action!
+ success = self._do_request(self._local_state)
+ # TODO error too often -> log critical to send mails
+ if success:
+ self._remote_state = self._local_state
+ self._last_set_at = now