Exemplo n.º 1
0
    def start_timer(self, event_id, attributes):
        timer_id = attributes["timerId"]
        existing_timer = self._timers.get(timer_id)
        if existing_timer and existing_timer.is_alive():
            # TODO 4 fail states are possible
            # TIMER_ID_ALREADY_IN_USE | OPEN_TIMERS_LIMIT_EXCEEDED | TIMER_CREATION_RATE_EXCEEDED | OPERATION_NOT_PERMITTED
            self._add_event(
                "StartTimerFailed",
                cause="TIMER_ID_ALREADY_IN_USE",
                decision_task_completed_event_id=event_id,
                timer_id=timer_id,
            )
            return

        time_to_wait = attributes["startToFireTimeout"]
        started_event_id = self._add_event(
            "TimerStarted",
            control=attributes.get("control"),
            decision_task_completed_event_id=event_id,
            start_to_fire_timeout=time_to_wait,
            timer_id=timer_id,
        ).event_id
        background_timer = ThreadingTimer(float(time_to_wait),
                                          self._fire_timer,
                                          args=(started_event_id, timer_id))
        workflow_timer = Timer(background_timer, started_event_id)
        self._timers[timer_id] = workflow_timer
        workflow_timer.start()
Exemplo n.º 2
0
def test_timer_cancel_delegates_to_wrapped_timer():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    background_timer.cancel = Mock()
    under_test = Timer(background_timer, "abc123")

    under_test.cancel()

    background_timer.cancel.assert_called_once()
Exemplo n.º 3
0
def test_timer_aliveness_delegates_to_wrapped_timer():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    background_timer.is_alive = Mock()
    under_test = Timer(background_timer, "abc123")

    under_test.is_alive()

    background_timer.is_alive.assert_called_once()
Exemplo n.º 4
0
 def set_timeout(self, func, time):
     timer_id = next_delay_id()
     t = ThreadingTimer(time / 1000.0, func)
     PynodeCoreGlobals.delay_object[timer_id] = t
     t.start()
     return timer_id
Exemplo n.º 5
0
def execute_interval_func(timer_id, func, time):
    t = ThreadingTimer(time / 1000.0, execute_interval_func,
                       (timer_id, func, time))
    PynodeCoreGlobals.delay_object[timer_id] = t
    t.start()
    func()
Exemplo n.º 6
0
def test_timer_creation():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    under_test = Timer(background_timer, "abc123")

    assert under_test.background_timer == background_timer
    assert under_test.started_event_id == "abc123"
Exemplo n.º 7
0
 def start(self):
     print("start")
     if not self.is_running:
         self._timer = ThreadingTimer(self.interval, self._run)
         self._timer.start()
         self.is_running = True