Skip to content

Commit b71ee99

Browse files
committed
ruff fixes
1 parent 803a813 commit b71ee99

File tree

5 files changed

+65
-51
lines changed

5 files changed

+65
-51
lines changed

backend/core/domain/resume.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,28 @@ def normalize_dates(cls, v: dict):
133133
val = v[field].strip()
134134
if val.lower() in ("present", "current", ""):
135135
v[field] = None
136-
elif match := re.match(r'(\d{2})\.(\d{4})', val): # MM.YYYY
136+
elif match := re.match(r"(\d{2})\.(\d{4})", val): # MM.YYYY
137137
month, year = match.groups()
138138
v[field] = f"{year}.{month}"
139-
elif match := re.match(r'([A-Za-z]{3})\s+(\d{4})', val): # MMM YYYY
139+
elif match := re.match(r"([A-Za-z]{3})\s+(\d{4})", val): # MMM YYYY
140140
month_name, year = match.groups()
141141
month_map = {
142-
'jan': '01', 'feb': '02', 'mar': '03', 'apr': '04',
143-
'may': '05', 'jun': '06', 'jul': '07', 'aug': '08',
144-
'sep': '09', 'oct': '10', 'nov': '11', 'dec': '12'
142+
"jan": "01",
143+
"feb": "02",
144+
"mar": "03",
145+
"apr": "04",
146+
"may": "05",
147+
"jun": "06",
148+
"jul": "07",
149+
"aug": "08",
150+
"sep": "09",
151+
"oct": "10",
152+
"nov": "11",
153+
"dec": "12",
145154
}
146-
month = month_map.get(month_name.lower()[:3], '01')
155+
month = month_map.get(month_name.lower()[:3], "01")
147156
v[field] = f"{year}.{month}"
148-
elif match := re.match(r'(\d{4})', val): # YYYY only
157+
elif match := re.match(r"(\d{4})", val): # YYYY only
149158
v[field] = f"{val}.01"
150159
return v
151160

@@ -246,19 +255,28 @@ def accept_legacy_education(cls, v: dict):
246255
val = v[field].strip()
247256
if val.lower() in ("present", "current", ""):
248257
v[field] = None
249-
elif match := re.match(r'(\d{2})\.(\d{4})', val): # MM.YYYY
258+
elif match := re.match(r"(\d{2})\.(\d{4})", val): # MM.YYYY
250259
month, year = match.groups()
251260
v[field] = f"{year}.{month}"
252-
elif match := re.match(r'([A-Za-z]{3})\s+(\d{4})', val): # MMM YYYY
261+
elif match := re.match(r"([A-Za-z]{3})\s+(\d{4})", val): # MMM YYYY
253262
month_name, year = match.groups()
254263
month_map = {
255-
'jan': '01', 'feb': '02', 'mar': '03', 'apr': '04',
256-
'may': '05', 'jun': '06', 'jul': '07', 'aug': '08',
257-
'sep': '09', 'oct': '10', 'nov': '11', 'dec': '12'
264+
"jan": "01",
265+
"feb": "02",
266+
"mar": "03",
267+
"apr": "04",
268+
"may": "05",
269+
"jun": "06",
270+
"jul": "07",
271+
"aug": "08",
272+
"sep": "09",
273+
"oct": "10",
274+
"nov": "11",
275+
"dec": "12",
258276
}
259-
month = month_map.get(month_name.lower()[:3], '01')
277+
month = month_map.get(month_name.lower()[:3], "01")
260278
v[field] = f"{year}.{month}"
261-
elif match := re.match(r'(\d{4})', val): # YYYY only
279+
elif match := re.match(r"(\d{4})", val): # YYYY only
262280
v[field] = f"{val}.01"
263281
if "start_date" in v and "start" not in v:
264282
v["start"] = v.pop("start_date")

backend/processor/services/file_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ async def _handle_durable_storage(temp_path: str, job_id: str, file_ext: str) ->
6464
temp_filename = f"{job_id}{file_ext}"
6565
durable_path = os.path.join(settings.UPLOAD_DIR, temp_filename)
6666
# For async file copy
67-
async with aiofiles.open(temp_path, 'rb') as src:
68-
async with aiofiles.open(durable_path, 'wb') as dst:
67+
async with aiofiles.open(temp_path, "rb") as src:
68+
async with aiofiles.open(durable_path, "wb") as dst:
6969
await dst.write(await src.read())
7070

7171
@staticmethod

backend/processor/utils/redis_queue.py

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ async def enqueue_job(self, job_id: str, file_path: str, task_data: dict | None
5151
pipeline.expire(task_key, settings.REDIS_JOB_TIMEOUT)
5252

5353
# Add to stream for instant delivery
54-
stream_data = {
55-
"task_id": task_id,
56-
"job_id": job_id,
57-
"priority": str(priority),
58-
"timestamp": str(time.time())
59-
}
54+
stream_data = {"task_id": task_id, "job_id": job_id, "priority": str(priority), "timestamp": str(time.time())}
6055
pipeline.xadd(self.job_stream, stream_data)
6156

6257
# Publish event for instant notification
@@ -78,9 +73,7 @@ async def get_redis(self) -> aioredis.Redis:
7873
)
7974
# Create consumer group if it doesn't exist
8075
try:
81-
await self.redis.xgroup_create(
82-
self.job_stream, self.consumer_group, id="0", mkstream=True
83-
)
76+
await self.redis.xgroup_create(self.job_stream, self.consumer_group, id="0", mkstream=True)
8477
except aioredis.ResponseError as e:
8578
if "BUSYGROUP" not in str(e):
8679
raise
@@ -97,7 +90,7 @@ async def consume_jobs(self) -> AsyncIterator[QueuedTask]:
9790
self.consumer_name,
9891
{self.job_stream: ">"},
9992
count=1,
100-
block=0 # Block indefinitely until message arrives
93+
block=0, # Block indefinitely until message arrives
10194
)
10295

10396
if not messages:
@@ -111,9 +104,7 @@ async def consume_jobs(self) -> AsyncIterator[QueuedTask]:
111104
job_data = await redis_client.hgetall(task_key)
112105
if job_data:
113106
# Acknowledge message
114-
await redis_client.xack(
115-
self.job_stream, self.consumer_group, msg_id
116-
)
107+
await redis_client.xack(self.job_stream, self.consumer_group, msg_id)
117108
yield QueuedTask.from_redis_dict(job_data)
118109

119110
except aioredis.ConnectionError:
@@ -127,10 +118,9 @@ async def mark_job_processing(self, task_id: str, job_id: str) -> bool:
127118

128119
pipeline = redis_client.pipeline()
129120
pipeline.hset(task_key, "status", "processing")
130-
pipeline.publish(f"cv:job:{job_id}:status", json.dumps({
131-
"status": "processing",
132-
"timestamp": datetime.now().isoformat()
133-
}))
121+
pipeline.publish(
122+
f"cv:job:{job_id}:status", json.dumps({"status": "processing", "timestamp": datetime.now().isoformat()})
123+
)
134124
results = await pipeline.execute()
135125
return bool(results[0] > 0)
136126

@@ -145,11 +135,10 @@ async def mark_job_completed(self, task_id: str, job_id: str, result: dict[str,
145135
pipeline.expire(task_key, 3600)
146136

147137
# Publish completion event for real-time updates
148-
pipeline.publish(f"cv:job:{job_id}:completed", json.dumps({
149-
"status": "completed",
150-
"job_id": job_id,
151-
"timestamp": datetime.now().isoformat()
152-
}))
138+
pipeline.publish(
139+
f"cv:job:{job_id}:completed",
140+
json.dumps({"status": "completed", "job_id": job_id, "timestamp": datetime.now().isoformat()}),
141+
)
153142

154143
await pipeline.execute()
155144
return True
@@ -187,11 +176,10 @@ async def mark_job_failed(self, task_id: str, job_id: str, error: str, retry: bo
187176
pipeline.expire(task_key, 86400)
188177

189178
# Publish failure event
190-
pipeline.publish(f"cv:job:{job_id}:failed", json.dumps({
191-
"status": "failed",
192-
"error": error,
193-
"timestamp": datetime.now().isoformat()
194-
}))
179+
pipeline.publish(
180+
f"cv:job:{job_id}:failed",
181+
json.dumps({"status": "failed", "error": error, "timestamp": datetime.now().isoformat()}),
182+
)
195183

196184
await pipeline.execute()
197185
return False
@@ -226,12 +214,15 @@ async def listen_for_retries(self):
226214
task_key = f"{self.task_key_prefix}{task_id}"
227215
job_data = await redis_client.hgetall(task_key)
228216
if job_data:
229-
await redis_client.xadd(self.job_stream, {
230-
"task_id": task_id,
231-
"job_id": job_data.get("job_id", ""),
232-
"priority": "1", # Higher priority for retries
233-
"timestamp": str(time.time())
234-
})
217+
await redis_client.xadd(
218+
self.job_stream,
219+
{
220+
"task_id": task_id,
221+
"job_id": job_data.get("job_id", ""),
222+
"priority": "1", # Higher priority for retries
223+
"timestamp": str(time.time()),
224+
},
225+
)
235226

236227
async def cleanup_expired_jobs(self, max_age_hours: int = 24) -> int:
237228
redis_client = await self.get_redis()

backend/processor/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ async def get(self, request, job_id):
8787

8888
class CleanupJobsView(APIView):
8989
@extend_schema(
90-
request={"application/json": {"type": "object", "properties": {"days": {"type": "integer"}, "force": {"type": "boolean"}}}},
90+
request={
91+
"application/json": {
92+
"type": "object",
93+
"properties": {"days": {"type": "integer"}, "force": {"type": "boolean"}},
94+
}
95+
},
9196
responses={200: OpenApiResponse(description="Cleanup result with deleted count")},
9297
description="Cleanup old jobs. Deletes jobs older than specified days. Use force=true to delete all jobs.",
9398
)

backend/search/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class JobExperienceSerializer(serializers.Serializer):
4141
required=False,
4242
allow_null=True,
4343
default=list,
44-
help_text="Key achievements/responsibilities"
44+
help_text="Key achievements/responsibilities",
4545
)
4646

4747

0 commit comments

Comments
 (0)