Skip to content

Commit

Permalink
feat: refactor tasks.py to handle scheduled and pending tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
versun committed Jul 5, 2024
1 parent a0ce0b2 commit 68d4905
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
unique_tasks = set()

def revoke_tasks_by_arg(arg_to_match):
for task in huey.scheduled():
for task in huey.scheduled() + huey.pending():
# Assuming the first argument is the one we're interested in (e.g., obj.pk)
if task.args and task.args[0] == arg_to_match:
logging.info("Revoke task: %s", task)
Expand All @@ -55,7 +55,7 @@ def cleanup_tasks():

@db_task(retries=3)
def update_original_feed(sid: str, force:bool = False):
if sid in unique_tasks:
if sid in unique_tasks: # 如果判断force的话,是没法停止正在执行的task
logging.warning("(skip)This task update_original_feed is executing: %s",sid)
return
else:
Expand Down Expand Up @@ -124,7 +124,7 @@ def update_original_feed(sid: str, force:bool = False):

@db_task(retries=3)
def update_translated_feed(sid: str, force:bool = False):
if sid in unique_tasks:
if sid in unique_tasks: # 如果判断force的话,是没法停止正在执行的task
logging.warning("(skip)The task update_translated_feed is executing: %s",sid)
return
else:
Expand All @@ -138,6 +138,7 @@ def update_translated_feed(sid: str, force:bool = False):
return False

try:
revoke_tasks_by_arg(sid)
logging.info("Call task update_translated_feed: %s", obj.o_feed.feed_url)

if obj.o_feed.pk is None:
Expand Down

0 comments on commit 68d4905

Please sign in to comment.