Fynjy
8 months ago
11 changed files with 470 additions and 347 deletions
@ -0,0 +1,3 @@ |
|||||||
|
from .celery import app as celery_app |
||||||
|
|
||||||
|
__all__ = ('celery_app') |
@ -0,0 +1,21 @@ |
|||||||
|
from __future__ import absolute_import, unicode_literals |
||||||
|
import os |
||||||
|
from celery import Celery |
||||||
|
from celery.schedules import crontab |
||||||
|
from crossposting_backend.tasks import delayed_post |
||||||
|
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crossposting_backend') |
||||||
|
|
||||||
|
app = Celery('crossposting_backend') |
||||||
|
app.config_from_object('django.conf:settings', namespace='CELERY') |
||||||
|
app.autodiscover_tasks() |
||||||
|
|
||||||
|
CELERY_BEAT_SCHEDULE = { |
||||||
|
# Задача, которая будет выполнять отложенные публикации |
||||||
|
'post-articles': { |
||||||
|
'task': 'crossposting_backend.tasks.delayed_post', |
||||||
|
'schedule': crontab(minute=0, hour='*'), # Запускать каждую минуту |
||||||
|
'args': () # Аргументы задачи, в данном случае их нет |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
from cms import promoters |
||||||
|
from cms.models import Article |
||||||
|
from celery import shared_task |
||||||
|
|
||||||
|
|
||||||
|
@shared_task |
||||||
|
def promote_post(article_id): |
||||||
|
article = Article.objects.get(id=article_id) |
||||||
|
article.is_published = True |
||||||
|
article.save() |
||||||
|
marketer = promoters.Marketer(article) |
||||||
|
marketer.promote() |
||||||
|
|
||||||
|
|
||||||
|
@shared_task |
||||||
|
def delayed_post(article_id, publication_time): |
||||||
|
article = Article.objects.get(id=article_id) |
||||||
|
celery_task = promote_post.apply_async(args=[article.id], eta=publication_time) |
||||||
|
return celery_task.id |
@ -0,0 +1,20 @@ |
|||||||
|
{% extends 'base.html' %} |
||||||
|
{% load bootstrap5 %} |
||||||
|
{% block content %} |
||||||
|
<div class="container"> |
||||||
|
<a href="{% url 'new-article' %}" class="btn btn-primary">Вернуться</a> |
||||||
|
|
||||||
|
{% for article in post %} |
||||||
|
<div class="card mb-3"> |
||||||
|
<div class="card-body"> |
||||||
|
<p class="card-text">{{ article.body }}</p> |
||||||
|
<a href="{{ article.link }}">{{ article.link }}</a> |
||||||
|
<p class="card-text"><small class="text-muted">Дата публикации: {{ article.publication_time }}</small></p> |
||||||
|
{% if user.is_authenticated %} |
||||||
|
<a href="{% url 'article_delete' article.id %}" class="btn btn-danger">Удалить</a> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
{% endblock content %} |
Loading…
Reference in new issue