Zelyanoth commited on
Commit
a34dd9e
·
1 Parent(s): 2b6471a

**Refactor job scheduling in `planifier_ligne` to use `functools.partial`**

Browse files

- Replace lambda functions with `partial` for better readability and maintainability
- Update job IDs to include `id_social` for better uniqueness and tracking

Files changed (1) hide show
  1. functi.py +5 -4
functi.py CHANGED
@@ -16,6 +16,7 @@ import requests
16
  from timing_lin import *
17
  from apscheduler.schedulers.background import BackgroundScheduler
18
  from apscheduler.triggers.cron import CronTrigger
 
19
 
20
  # Create the scheduler globally (start it once)
21
  apsched = BackgroundScheduler()
@@ -237,16 +238,16 @@ def planifier_ligne(id_schedule, id_social, user_id, schedule_time_str, ss, adju
237
 
238
  # Schedule publishing
239
  apsched.add_job(
240
- lambda: post_publishing_for_robot(id_social, user_id, id_schedule, ss),
241
  CronTrigger(day_of_week=day_map[jour_key], hour=hour, minute=minute),
242
- id=f"pub-{id_schedule}-{schedule_time_str}"
243
  )
244
 
245
  # Schedule generation
246
  apsched.add_job(
247
- lambda: post_generation_for_robot(user_id, id_social, id_schedule),
248
  CronTrigger(day_of_week=day_map[jour_key_adj], hour=hour_adj, minute=minute_adj),
249
- id=f"gen-{id_schedule}-{schedule_time_str}"
250
  )
251
 
252
  print(f"⏳ APScheduler: Tâche planifiée pour {id_social} ({user_id}) le {jour} à {hour:02d}:{minute:02d} et {jour_adj} à {hour_adj:02d}:{minute_adj:02d}", flush=True)
 
16
  from timing_lin import *
17
  from apscheduler.schedulers.background import BackgroundScheduler
18
  from apscheduler.triggers.cron import CronTrigger
19
+ from functools import partial
20
 
21
  # Create the scheduler globally (start it once)
22
  apsched = BackgroundScheduler()
 
238
 
239
  # Schedule publishing
240
  apsched.add_job(
241
+ partial(post_publishing_for_robot, id_social, user_id, id_schedule, ss),
242
  CronTrigger(day_of_week=day_map[jour_key], hour=hour, minute=minute),
243
+ id=f"pub-{id_schedule}-{schedule_time_str}--{id_social}"
244
  )
245
 
246
  # Schedule generation
247
  apsched.add_job(
248
+ partial(post_generation_for_robot, user_id, id_social, id_schedule),
249
  CronTrigger(day_of_week=day_map[jour_key_adj], hour=hour_adj, minute=minute_adj),
250
+ id=f"gen-{id_schedule}-{schedule_time_str}--{id_social}"
251
  )
252
 
253
  print(f"⏳ APScheduler: Tâche planifiée pour {id_social} ({user_id}) le {jour} à {hour:02d}:{minute:02d} et {jour_adj} à {hour_adj:02d}:{minute_adj:02d}", flush=True)