On ajoute un bouton pour ne relancer que les imports échoués

This commit is contained in:
Jean-Marie Favreau 2024-09-07 15:00:33 +02:00
parent b6821436e9
commit f38d4bee97
5 changed files with 58 additions and 4 deletions

View File

@ -174,7 +174,7 @@ def run_recurrent_import(self, pk):
def daily_imports(self):
from agenda_culturel.models import RecurrentImport
logger.info("Imports quotidiens")
logger.info("Everyday imports")
imports = RecurrentImport.objects.filter(
recurrence=RecurrentImport.RECURRENCE.DAILY
)
@ -187,18 +187,30 @@ def daily_imports(self):
def run_all_recurrent_imports(self):
from agenda_culturel.models import RecurrentImport
logger.info("Imports complets")
logger.info("Run all imports")
imports = RecurrentImport.objects.all()
for imp in imports:
run_recurrent_import.delay(imp.pk)
@app.task(bind=True)
def run_all_recurrent_imports_failed(self):
from agenda_culturel.models import RecurrentImport, BatchImportation
logger.info("Run only failed imports")
imports = RecurrentImport.objects.all()
for imp in imports:
if imp.last_import().status == BatchImportation.STATUS.FAILED:
run_recurrent_import.delay(imp.pk)
@app.task(bind=True)
def weekly_imports(self):
from agenda_culturel.models import RecurrentImport
logger.info("Imports hebdomadaires")
logger.info("Weekly imports")
imports = RecurrentImport.objects.filter(
recurrence=RecurrentImport.RECURRENCE.WEEKLY
)

View File

@ -13,7 +13,8 @@
<article>
<header>
<div class="slide-buttons">
<a href="{% url 'run_all_rimports'%}" role="button">Exécuter tous</a>
<a href="{% url 'run_all_rimports' %}" role="button">Importer tout {% picto_from_name "play-circle" %}</a>
<a href="{% url 'run_all_rimports_failed' %}" role="button">Relancer les imports échoués {% picto_from_name "play-circle" %}</a>
<a href="{% url 'add_rimport'%}" role="button">Ajouter {% picto_from_name "plus-circle" %}</a>
</div>
<h1>Importations récurrentes</h1>

View File

@ -0,0 +1,25 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}{% block og_title %}Lancer tous les imports{% endblock %}{% endblock %}
{% block content %}
<article>
<header>
<h1>Lancement des imports en échec</h1>
</header>
<form method="post">{% csrf_token %}
<p>Êtes-vous sûr·e de vouloir lancer tous les imports récurrent ayant échoué lors du dernier import&nbsp;?</p>
{{ form }}
<footer>
<div class="grid buttons">
<a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{% url 'recurrent_imports' %}{% endif %}" role="button" class="secondary">Annuler</a>
<input type="submit" value="Confirmer">
</div>
</footer>
</form>
</article>
{% endblock %}

View File

@ -71,6 +71,7 @@ urlpatterns = [
path("imports/<int:pk>/cancel", cancel_import, name="cancel_import"),
path("rimports/", recurrent_imports, name="recurrent_imports"),
path("rimports/run", run_all_rimports, name="run_all_rimports"),
path("rimports/failed/run", run_all_rimports_failed, name="run_all_rimports_failed"),
path("rimports/add", RecurrentImportCreateView.as_view(), name="add_rimport"),
path("rimports/<int:pk>/view", view_rimport, name="view_rimport"),
path(

View File

@ -73,6 +73,7 @@ from .celery import (
import_events_from_json,
run_recurrent_import,
run_all_recurrent_imports,
run_all_recurrent_imports_failed,
import_events_from_url,
import_events_from_urls,
)
@ -1190,6 +1191,20 @@ def run_all_rimports(request):
else:
return render(request, "agenda_culturel/run_all_rimports_confirm.html")
@login_required(login_url="/accounts/login/")
@permission_required(
["agenda_culturel.view_recurrentimport", "agenda_culturel.run_recurrentimport"]
)
def run_all_rimports_failed(request):
if request.method == "POST":
# run recurrent import
run_all_recurrent_imports_failed.delay()
messages.success(request, _("Imports has been launched."))
return HttpResponseRedirect(reverse_lazy("recurrent_imports"))
else:
return render(request, "agenda_culturel/run_failed_rimports_confirm.html")
#########################
## duplicated events