Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Refactor job handling into single function
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-christensen committed Aug 11, 2019
1 parent 88180d9 commit ab584c5
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,18 @@
q = Queue(connection=Redis())


def start_job(resource_value: str, resource_type: str):
return q.enqueue(
convert_resource,
resource_value,
resource_type,
job_id=resource_value,
job_timeout="1h",
result_ttl=30,
)


def handle_job(resource_id: str, resource_type: str) -> dict:
def handle_job(resource_value: str, resource_type: str) -> dict:
try:
job = Job.fetch(resource_id, connection=Redis())
job = Job.fetch(resource_value, connection=Redis())
except NoSuchJobError:
job = start_job(resource_id, resource_type)
job = q.enqueue(
convert_resource,
resource_value,
resource_type,
job_id=resource_value,
job_timeout="1h",
result_ttl=30,
)
return {"Status": "Started"}

if job.result:
Expand Down

0 comments on commit ab584c5

Please sign in to comment.