подправил логику работы проги
All checks were successful
Deploy timelaps / deploy (push) Successful in 5s

This commit is contained in:
ack
2026-04-19 22:37:04 +03:00
parent 036797d94a
commit 34440ebf73
3 changed files with 16 additions and 4 deletions

View File

@@ -1,9 +1,19 @@
from datetime import timedelta
from django import forms from django import forms
from django.utils import timezone
from .models import TimelapseJob from .models import TimelapseJob
class TimelapseJobCreateForm(forms.ModelForm): 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: class Meta:
model = TimelapseJob model = TimelapseJob
fields = ( fields = (

View File

@@ -2,7 +2,7 @@
{% block content %} {% block content %}
{% if has_active_jobs %} {% if has_active_jobs %}
<meta http-equiv="refresh" content="5"> <meta http-equiv="refresh" content="2">
{% endif %} {% endif %}
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="d-flex justify-content-between align-items-center mb-4">
<h2>Очередь задач</h2> <h2>Очередь задач</h2>
@@ -25,6 +25,8 @@
<div class="alert alert-success py-2">Воркер очереди запущен. Обнови страницу через несколько секунд.</div> <div class="alert alert-success py-2">Воркер очереди запущен. Обнови страницу через несколько секунд.</div>
{% elif queue_started == 'error' %} {% elif queue_started == 'error' %}
<div class="alert alert-danger py-2">Не удалось запустить воркер. Проверь логи Django.</div> <div class="alert alert-danger py-2">Не удалось запустить воркер. Проверь логи Django.</div>
{% elif queue_started == 'running' %}
<div class="alert alert-warning py-2">Задача уже выполняется.</div>
{% elif queue_started %} {% elif queue_started %}
<div class="alert alert-success py-2">Запущена задача #{{ queue_started }}.</div> <div class="alert alert-success py-2">Запущена задача #{{ queue_started }}.</div>
{% endif %} {% endif %}

View File

@@ -193,7 +193,7 @@ def run_job_now(request, job_id: int):
if job.status == TimelapseJob.Status.RUNNING: if job.status == TimelapseJob.Status.RUNNING:
logger.info('job:run_now:done job_id=%s blocked=running', job_id) 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)] cmd = [sys.executable, 'manage.py', 'run_timelapse_worker', '--job-id', str(job_id)]
kwargs = { kwargs = {
@@ -208,10 +208,10 @@ def run_job_now(request, job_id: int):
try: try:
subprocess.Popen(cmd, **kwargs) subprocess.Popen(cmd, **kwargs)
logger.info('job:run_now:done job_id=%s worker_started=true', job_id) 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: except Exception:
logger.exception('job:run_now:error job_id=%s', job_id) 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): def job_create(request, camera_id: int):