Пример #1
0
 def test_get_in_progress_rhic_lookups(self):
     # Create a valid, in_progress task
     task_a = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False)
     task_a.save()
     # Create a completed task
     task_b = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a22222222222", completed=True,
         initiated=datetime.now(tzutc()),
         modified=datetime.now(tzutc()))
     task_b.save()
     # Create a timedout incomplete task
     cfg = config.get_rhic_serve_config_info()
     timeout_in_minutes = cfg["single_rhic_lookup_timeout_in_minutes"]
     expired_time = datetime.now(tzutc()) - timedelta(minutes=timeout_in_minutes+1)
     task_c = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a333333333333", completed=False, initiated=expired_time)
     task_c.save()
     current_tasks = identity.get_in_progress_rhic_lookups()
     self.assertEquals(len(current_tasks), 1)
     self.assertEquals(current_tasks[0].uuid, task_a.uuid)
Пример #2
0
def process_running_rhic_lookup_tasks():
    start = time.time()
    _LOG.info("invoked")
    identity.purge_expired_rhic_lookups()
    in_progress_tasks = identity.get_in_progress_rhic_lookups()
    _LOG.info("%s in progress tasks exist" % (len(in_progress_tasks)))
    for t in in_progress_tasks:
        if t.task_id:
            result = AsyncResult(t.task_id)
            if result.state in ["RUNNING", "PENDING"]:
                _LOG.info("skipped '%s' since it is %s" % (t, result.state))
                continue
            else:
                _LOG.info("found existing "
                          "celery task with id '%s' and state '%s'.  Will issue a new task "
                          "since state was not RUNNING or PENDING." % (t.task_id, result.state))
        new_result = sync_single_rhic.apply_async((t.uuid,))
        new_task = identity_lookup.update_rhic_lookup_task(t.uuid, new_result.task_id)
        _LOG.info("initiated new task: %s" % (new_task))
    end = time.time()
    _LOG.info("completed in %s seconds" % (end-start))