-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(feat): add fixes to relatedArticles logic
- Loading branch information
ndu
committed
Dec 12, 2024
1 parent
b2d40ef
commit 996d3a6
Showing
5 changed files
with
201 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
from celery import shared_task | ||
from django.utils import timezone | ||
from django.db import transaction | ||
from .models import Article | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# TODO: Implement Querying the Articles in chunks in case of very large dataset | ||
@shared_task | ||
@shared_task(name='apps.research.tasks.publish_scheduled_articles') | ||
def publish_scheduled_articles(): | ||
"""Publish articles that are scheduled to be published.""" | ||
now = timezone.now() | ||
articles_to_publish = Article.objects.filter(status='draft', scheduled_publish_time__lte=now) | ||
articles_to_publish.update(status='ready') | ||
""" | ||
Update status of draft articles that have reached their scheduled publish time | ||
""" | ||
try: | ||
with transaction.atomic(): | ||
updated = Article.objects.filter( | ||
status='draft', | ||
scheduled_publish_time__isnull=False, | ||
scheduled_publish_time__lte=timezone.now() | ||
).update(status='ready') | ||
|
||
if updated: | ||
logger.info(f"Updated {updated} articles to ready status") | ||
|
||
return updated | ||
|
||
except Exception as e: | ||
logger.error(f"Error publishing scheduled articles: {e}") | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters