backend/celery_tasks/content_tasks.py
CHANGED
|
@@ -22,6 +22,7 @@ def generate_content_task(self, user_id: str, schedule_id: str, supabase_client_
|
|
| 22 |
dict: Result of content generation
|
| 23 |
"""
|
| 24 |
try:
|
|
|
|
| 25 |
logger.info(f"Starting content generation for schedule {schedule_id}")
|
| 26 |
|
| 27 |
# Update task state
|
|
@@ -102,6 +103,7 @@ def publish_post_task(self, schedule_id: str, supabase_client_config: dict):
|
|
| 102 |
dict: Result of post publishing
|
| 103 |
"""
|
| 104 |
try:
|
|
|
|
| 105 |
logger.info(f"Starting post publishing for schedule {schedule_id}")
|
| 106 |
|
| 107 |
# Update task state
|
|
|
|
| 22 |
dict: Result of content generation
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
+
print(f"[CONTENT TASK] Starting content generation for schedule {schedule_id}")
|
| 26 |
logger.info(f"Starting content generation for schedule {schedule_id}")
|
| 27 |
|
| 28 |
# Update task state
|
|
|
|
| 103 |
dict: Result of post publishing
|
| 104 |
"""
|
| 105 |
try:
|
| 106 |
+
print(f"[PUBLISH TASK] Starting post publishing for schedule {schedule_id}")
|
| 107 |
logger.info(f"Starting post publishing for schedule {schedule_id}")
|
| 108 |
|
| 109 |
# Update task state
|
backend/celery_tasks/schedule_loader.py
CHANGED
|
@@ -28,6 +28,7 @@ def parse_schedule_time(schedule_time):
|
|
| 28 |
dict: Crontab parameters
|
| 29 |
"""
|
| 30 |
try:
|
|
|
|
| 31 |
day_name, time_str = schedule_time.split()
|
| 32 |
hour, minute = map(int, time_str.split(':'))
|
| 33 |
|
|
@@ -43,12 +44,13 @@ def parse_schedule_time(schedule_time):
|
|
| 43 |
}
|
| 44 |
|
| 45 |
day_of_week = day_map.get(day_name, '*')
|
| 46 |
-
|
| 47 |
-
return {
|
| 48 |
'minute': minute,
|
| 49 |
'hour': hour,
|
| 50 |
'day_of_week': day_of_week
|
| 51 |
}
|
|
|
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
logger.error(f"Error parsing schedule time {schedule_time}: {str(e)}")
|
| 54 |
# Default to every minute for error cases
|
|
@@ -133,13 +135,21 @@ def load_schedules_task(self):
|
|
| 133 |
|
| 134 |
# Create content generation job (5 minutes before publishing)
|
| 135 |
gen_job_id = f"gen_{schedule_id}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
new_schedule[gen_job_id] = {
|
| 137 |
'task': 'backend.celery_tasks.content_tasks.generate_content_task',
|
| 138 |
-
'schedule':
|
| 139 |
-
minute=content_gen_time['minute'],
|
| 140 |
-
hour=content_gen_time['hour'],
|
| 141 |
-
day_of_week=content_gen_time['day_of_week']
|
| 142 |
-
),
|
| 143 |
'args': (
|
| 144 |
schedule.get('Social_network', {}).get('id_utilisateur'),
|
| 145 |
schedule_id,
|
|
@@ -151,13 +161,20 @@ def load_schedules_task(self):
|
|
| 151 |
|
| 152 |
# Create publishing job
|
| 153 |
pub_job_id = f"pub_{schedule_id}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
new_schedule[pub_job_id] = {
|
| 155 |
'task': 'backend.celery_tasks.content_tasks.publish_post_task',
|
| 156 |
-
'schedule':
|
| 157 |
-
minute=publish_time['minute'],
|
| 158 |
-
hour=publish_time['hour'],
|
| 159 |
-
day_of_week=publish_time['day_of_week']
|
| 160 |
-
),
|
| 161 |
'args': (
|
| 162 |
schedule_id,
|
| 163 |
supabase_config
|
|
@@ -170,6 +187,8 @@ def load_schedules_task(self):
|
|
| 170 |
logger.error(f"Error creating jobs for schedule {schedule.get('id')}: {str(e)}")
|
| 171 |
|
| 172 |
# Update the beat schedule
|
|
|
|
|
|
|
| 173 |
current_app.conf.beat_schedule = new_schedule
|
| 174 |
print(f"[CELERY BEAT] Successfully updated Celery Beat schedule with {len(new_schedule)} jobs")
|
| 175 |
logger.info("Updated Celery Beat schedule")
|
|
|
|
| 28 |
dict: Crontab parameters
|
| 29 |
"""
|
| 30 |
try:
|
| 31 |
+
print(f"[CELERY BEAT] Parsing schedule time: {schedule_time}")
|
| 32 |
day_name, time_str = schedule_time.split()
|
| 33 |
hour, minute = map(int, time_str.split(':'))
|
| 34 |
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
day_of_week = day_map.get(day_name, '*')
|
| 47 |
+
result = {
|
|
|
|
| 48 |
'minute': minute,
|
| 49 |
'hour': hour,
|
| 50 |
'day_of_week': day_of_week
|
| 51 |
}
|
| 52 |
+
print(f"[CELERY BEAT] Parsed schedule time result: {result}")
|
| 53 |
+
return result
|
| 54 |
except Exception as e:
|
| 55 |
logger.error(f"Error parsing schedule time {schedule_time}: {str(e)}")
|
| 56 |
# Default to every minute for error cases
|
|
|
|
| 135 |
|
| 136 |
# Create content generation job (5 minutes before publishing)
|
| 137 |
gen_job_id = f"gen_{schedule_id}"
|
| 138 |
+
task_schedule = crontab(
|
| 139 |
+
minute=content_gen_time['minute'],
|
| 140 |
+
hour=content_gen_time['hour'],
|
| 141 |
+
day_of_week=content_gen_time['day_of_week']
|
| 142 |
+
)
|
| 143 |
+
print(f"[CELERY BEAT] Creating content task - ID: {gen_job_id}")
|
| 144 |
+
print(f"[CELERY BEAT] Content task schedule: minute={content_gen_time['minute']}, hour={content_gen_time['hour']}, day_of_week={content_gen_time['day_of_week']}")
|
| 145 |
+
print(f"[CELERY BEAT] Content task args: {(
|
| 146 |
+
schedule.get('Social_network', {}).get('id_utilisateur'),
|
| 147 |
+
schedule_id,
|
| 148 |
+
supabase_config
|
| 149 |
+
)}")
|
| 150 |
new_schedule[gen_job_id] = {
|
| 151 |
'task': 'backend.celery_tasks.content_tasks.generate_content_task',
|
| 152 |
+
'schedule': task_schedule,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
'args': (
|
| 154 |
schedule.get('Social_network', {}).get('id_utilisateur'),
|
| 155 |
schedule_id,
|
|
|
|
| 161 |
|
| 162 |
# Create publishing job
|
| 163 |
pub_job_id = f"pub_{schedule_id}"
|
| 164 |
+
task_schedule = crontab(
|
| 165 |
+
minute=publish_time['minute'],
|
| 166 |
+
hour=publish_time['hour'],
|
| 167 |
+
day_of_week=publish_time['day_of_week']
|
| 168 |
+
)
|
| 169 |
+
print(f"[CELERY BEAT] Creating publish task - ID: {pub_job_id}")
|
| 170 |
+
print(f"[CELERY BEAT] Publish task schedule: minute={publish_time['minute']}, hour={publish_time['hour']}, day_of_week={publish_time['day_of_week']}")
|
| 171 |
+
print(f"[CELERY BEAT] Publish task args: {(
|
| 172 |
+
schedule_id,
|
| 173 |
+
supabase_config
|
| 174 |
+
)}")
|
| 175 |
new_schedule[pub_job_id] = {
|
| 176 |
'task': 'backend.celery_tasks.content_tasks.publish_post_task',
|
| 177 |
+
'schedule': task_schedule,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
'args': (
|
| 179 |
schedule_id,
|
| 180 |
supabase_config
|
|
|
|
| 187 |
logger.error(f"Error creating jobs for schedule {schedule.get('id')}: {str(e)}")
|
| 188 |
|
| 189 |
# Update the beat schedule
|
| 190 |
+
print(f"[CELERY BEAT] Current schedule keys before update: {list(current_app.conf.beat_schedule.keys())}")
|
| 191 |
+
print(f"[CELERY BEAT] New schedule keys: {list(new_schedule.keys())}")
|
| 192 |
current_app.conf.beat_schedule = new_schedule
|
| 193 |
print(f"[CELERY BEAT] Successfully updated Celery Beat schedule with {len(new_schedule)} jobs")
|
| 194 |
logger.info("Updated Celery Beat schedule")
|