Exemple #1
0
    def test_purge_expired_rhic_lookups(self):
        cfg = config.get_rhic_serve_config_info()
        # 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
        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()
        # Create a completed expired task
        expired_hours = cfg["single_rhic_lookup_cache_unknown_in_hours"]
        expired_time = datetime.now(tzutc()) - timedelta(hours=expired_hours+1)
        task_d = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a444444444444", completed=True, modified=expired_time)
        task_d.save()

        identity.purge_expired_rhic_lookups()
        found = RHICLookupTask.objects()
        self.assertEquals(len(found), 2)
        for f in found:
            self.assertTrue(f.uuid in [task_a.uuid, task_b.uuid])
            self.assertTrue(f.uuid not in [task_c.uuid, task_d.uuid])
Exemple #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))