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))
def test_update_rhic_lookup_task(self): task_a = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False, task_id=None) task_a.save() found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(task_a.uuid, found[0].uuid) self.assertIsNone(found[0].task_id) prior_modified = task_a.modified # Ensure that 'modified' has been updated to new time # and the 'task_id' has been noted task_id = "1" ret_val = identity_lookup.update_rhic_lookup_task(task_a.uuid, task_id) self.assertEquals(ret_val.uuid, task_a.uuid) self.assertFalse(ret_val.completed) self.assertEquals(ret_val.task_id, task_id) self.assertTrue(ret_val.modified > prior_modified) found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task_a.uuid) self.assertFalse(found[0].completed) self.assertEquals(found[0].task_id, task_id) self.assertTrue(found[0].modified > prior_modified)