Esempio n. 1
0
    def test_task_decorator_adds_callable_to_registry(self):
        TIEMPO_REGISTRY.clear()

        task = Task(priority=1, periodic=True, force_interval=1)
        decorated = task(some_callable)  # Pushes onto registry dict

        self.assertEqual(len(TIEMPO_REGISTRY), 1)  # Our task it the only one in the dict.

        key = TIEMPO_REGISTRY.keys()[0]  # Grab the key...

        self.assertEqual(key.split(".")[-1], "some_callable")  # And sure enough, it matches our callable.
Esempio n. 2
0
    def test_task_decorator_adds_callable_to_registry(self):
        TIEMPO_REGISTRY.clear()

        task = Task(priority=1, periodic=True, force_interval=1)
        decorated = task(some_callable)  # Pushes onto registry dict

        self.assertEqual(len(TIEMPO_REGISTRY),
                         1)  # Our task it the only one in the dict.

        key = TIEMPO_REGISTRY.keys()[0]  # Grab the key...

        self.assertEqual(
            key.split('.')[-1],
            'some_callable')  # And sure enough, it matches our callable.
Esempio n. 3
0
def run():
    this_loop_runtime = utc_now()

    # This loop basically does two things:
    for runner in all_runners():
        # 1) Let the runners pick up any queued tasks.
        result = runner.run()

        if not result in (BUSY, IDLE):
            # If the runner is neither busy nor idle, it will have returned a Deferred.
            result.addCallback(runner.finish_job)


    # 2) Queue up new tasks.
    for task_string, task in TIEMPO_REGISTRY.items():

        ### REPLACE with task.next_expiration_dt()
        if hasattr(task, 'force_interval'):
            expire_key = this_loop_runtime + datetime.timedelta(
                    seconds=task.force_interval
            )
        else:
            expire_key = task_time_keys().get(task.get_schedule())
        #########

        if expire_key:
            stop_key_has_expired = REDIS.setnx(task.stop_key, 0)

            if stop_key_has_expired:

                REDIS.expire(
                    task.stop_key,
                    int(float((expire_key - this_loop_runtime).total_seconds())) - 1
                )

                # OK, we're ready to queue up a new job for this task!
                task.spawn_job()