подправил логику работы проги
All checks were successful
Deploy timelaps / deploy (push) Successful in 5s
All checks were successful
Deploy timelaps / deploy (push) Successful in 5s
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django import forms
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import TimelapseJob
|
||||
|
||||
|
||||
class TimelapseJobCreateForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not self.is_bound:
|
||||
today = timezone.localdate()
|
||||
self.initial.setdefault('date_to', today)
|
||||
self.initial.setdefault('date_from', today - timedelta(days=7))
|
||||
|
||||
class Meta:
|
||||
model = TimelapseJob
|
||||
fields = (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
{% if has_active_jobs %}
|
||||
<meta http-equiv="refresh" content="5">
|
||||
<meta http-equiv="refresh" content="2">
|
||||
{% endif %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2>Очередь задач</h2>
|
||||
@@ -25,6 +25,8 @@
|
||||
<div class="alert alert-success py-2">Воркер очереди запущен. Обнови страницу через несколько секунд.</div>
|
||||
{% elif queue_started == 'error' %}
|
||||
<div class="alert alert-danger py-2">Не удалось запустить воркер. Проверь логи Django.</div>
|
||||
{% elif queue_started == 'running' %}
|
||||
<div class="alert alert-warning py-2">Задача уже выполняется.</div>
|
||||
{% elif queue_started %}
|
||||
<div class="alert alert-success py-2">Запущена задача #{{ queue_started }}.</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -193,7 +193,7 @@ def run_job_now(request, job_id: int):
|
||||
|
||||
if job.status == TimelapseJob.Status.RUNNING:
|
||||
logger.info('job:run_now:done job_id=%s blocked=running', job_id)
|
||||
return redirect(f"{reverse('camlaps:job_detail', kwargs={'job_id': job_id})}?run_now=running")
|
||||
return redirect(f"{reverse('camlaps:job_list')}?started=running")
|
||||
|
||||
cmd = [sys.executable, 'manage.py', 'run_timelapse_worker', '--job-id', str(job_id)]
|
||||
kwargs = {
|
||||
@@ -208,10 +208,10 @@ def run_job_now(request, job_id: int):
|
||||
try:
|
||||
subprocess.Popen(cmd, **kwargs)
|
||||
logger.info('job:run_now:done job_id=%s worker_started=true', job_id)
|
||||
return redirect(f"{reverse('camlaps:job_detail', kwargs={'job_id': job_id})}?run_now=started")
|
||||
return redirect(f"{reverse('camlaps:job_list')}?started={job_id}")
|
||||
except Exception:
|
||||
logger.exception('job:run_now:error job_id=%s', job_id)
|
||||
return redirect(f"{reverse('camlaps:job_detail', kwargs={'job_id': job_id})}?run_now=error")
|
||||
return redirect(f"{reverse('camlaps:job_list')}?started=error")
|
||||
|
||||
|
||||
def job_create(request, camera_id: int):
|
||||
|
||||
Reference in New Issue
Block a user