explicitly mark helper functions private

I thought about making them private class members, but that would get
unreadable and do more harm than good.
This commit is contained in:
Houkime 2022-11-30 16:22:46 +00:00
parent 870d2c408d
commit 14c4ae26ab

View file

@ -98,7 +98,7 @@ class Jobs:
result=None, result=None,
) )
r = RedisPool().get_connection() r = RedisPool().get_connection()
store_job_as_hash(r, redis_key_from_uuid(job.uid), job) _store_job_as_hash(r, _redis_key_from_uuid(job.uid), job)
return job return job
@staticmethod @staticmethod
@ -114,7 +114,7 @@ class Jobs:
Remove a job from the jobs list. Remove a job from the jobs list.
""" """
r = RedisPool().get_connection() r = RedisPool().get_connection()
key = redis_key_from_uuid(job_uuid) key = _redis_key_from_uuid(job_uuid)
r.delete(key) r.delete(key)
return False return False
@ -148,9 +148,9 @@ class Jobs:
job.finished_at = datetime.datetime.now() job.finished_at = datetime.datetime.now()
r = RedisPool().get_connection() r = RedisPool().get_connection()
key = redis_key_from_uuid(job.uid) key = _redis_key_from_uuid(job.uid)
if r.exists(key): if r.exists(key):
store_job_as_hash(r, key, job) _store_job_as_hash(r, key, job)
if status in (JobStatus.FINISHED, JobStatus.ERROR): if status in (JobStatus.FINISHED, JobStatus.ERROR):
r.expire(key, JOB_EXPIRATION_SECONDS) r.expire(key, JOB_EXPIRATION_SECONDS)
@ -162,9 +162,9 @@ class Jobs:
Get a job from the jobs list. Get a job from the jobs list.
""" """
r = RedisPool().get_connection() r = RedisPool().get_connection()
key = redis_key_from_uuid(uid) key = _redis_key_from_uuid(uid)
if r.exists(key): if r.exists(key):
return job_from_hash(r, key) return _job_from_hash(r, key)
return None return None
@staticmethod @staticmethod
@ -174,7 +174,7 @@ class Jobs:
""" """
r = RedisPool().get_connection() r = RedisPool().get_connection()
jobs = r.keys("jobs:*") jobs = r.keys("jobs:*")
return [job_from_hash(r, job_key) for job_key in jobs] return [_job_from_hash(r, job_key) for job_key in jobs]
@staticmethod @staticmethod
def is_busy() -> bool: def is_busy() -> bool:
@ -187,11 +187,11 @@ class Jobs:
return False return False
def redis_key_from_uuid(uuid): def _redis_key_from_uuid(uuid):
return "jobs:" + str(uuid) return "jobs:" + str(uuid)
def store_job_as_hash(r, redis_key, model): def _store_job_as_hash(r, redis_key, model):
for key, value in model.dict().items(): for key, value in model.dict().items():
if isinstance(value, uuid.UUID): if isinstance(value, uuid.UUID):
value = str(value) value = str(value)
@ -202,7 +202,7 @@ def store_job_as_hash(r, redis_key, model):
r.hset(redis_key, key, str(value)) r.hset(redis_key, key, str(value))
def job_from_hash(r, redis_key): def _job_from_hash(r, redis_key):
if r.exists(redis_key): if r.exists(redis_key):
job_dict = r.hgetall(redis_key) job_dict = r.hgetall(redis_key)
for date in [ for date in [