From 14c4ae26abc3916fc3f792f012a83ee1e327a2cd Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 30 Nov 2022 16:22:46 +0000 Subject: [PATCH] explicitly mark helper functions private I thought about making them private class members, but that would get unreadable and do more harm than good. --- selfprivacy_api/jobs/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/selfprivacy_api/jobs/__init__.py b/selfprivacy_api/jobs/__init__.py index a3007a4..6ad8493 100644 --- a/selfprivacy_api/jobs/__init__.py +++ b/selfprivacy_api/jobs/__init__.py @@ -98,7 +98,7 @@ class Jobs: result=None, ) 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 @staticmethod @@ -114,7 +114,7 @@ class Jobs: Remove a job from the jobs list. """ r = RedisPool().get_connection() - key = redis_key_from_uuid(job_uuid) + key = _redis_key_from_uuid(job_uuid) r.delete(key) return False @@ -148,9 +148,9 @@ class Jobs: job.finished_at = datetime.datetime.now() r = RedisPool().get_connection() - key = redis_key_from_uuid(job.uid) + key = _redis_key_from_uuid(job.uid) 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): r.expire(key, JOB_EXPIRATION_SECONDS) @@ -162,9 +162,9 @@ class Jobs: Get a job from the jobs list. """ r = RedisPool().get_connection() - key = redis_key_from_uuid(uid) + key = _redis_key_from_uuid(uid) if r.exists(key): - return job_from_hash(r, key) + return _job_from_hash(r, key) return None @staticmethod @@ -174,7 +174,7 @@ class Jobs: """ r = RedisPool().get_connection() 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 def is_busy() -> bool: @@ -187,11 +187,11 @@ class Jobs: return False -def redis_key_from_uuid(uuid): +def _redis_key_from_uuid(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(): if isinstance(value, uuid.UUID): value = str(value) @@ -202,7 +202,7 @@ def store_job_as_hash(r, redis_key, model): 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): job_dict = r.hgetall(redis_key) for date in [