feat(queue): publish queue with slots, /plan page and dry-run runner

This commit is contained in:
kpa39l
2026-10-30 19:10:51 +00:00
parent 6a78b6c0a2
commit fba0e395b6
23 changed files with 1013 additions and 69 deletions
+1
View File
@@ -66,6 +66,7 @@
<div class="text-sm text-neutral-500 mb-1">⚡ Массовые операции <span class="badge badge-neutral" id="sel-count" x-text="ids.size">0</span></div>
<div class="join w-full flex-wrap">
<button class="join-item flex-1 btn btn-sm btn-info" name="action" value="process">🤖 Обработать моделью</button>
<button class="join-item flex-1 btn btn-sm" name="action" value="enqueue">🗓 В очередь</button>
<button class="join-item flex-1 btn btn-sm" name="action" value="rewrite">✍️ Переписать</button>
<button class="join-item flex-1 btn btn-sm btn-success" name="action" value="approve">✅ Опубликовать</button>
<button class="join-item flex-1 btn btn-sm btn-outline text-red-600" name="action" value="reject">🚫 Отклонить</button>
+1
View File
@@ -13,6 +13,7 @@
<nav class="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm">
<a class="no-underline text-neutral-300 hover:text-white" href="/candidates">Кандидаты</a>
<a class="no-underline text-neutral-300 hover:text-white" href="/selected">⭐ Отобранные</a>
<a class="no-underline text-neutral-300 hover:text-white" href="/plan">🗓 План</a>
<a class="no-underline text-neutral-300 hover:text-white" href="/published">Опубликовано</a>
<a class="no-underline text-neutral-300 hover:text-white" href="/metrics">Метрики</a>
<a class="no-underline text-neutral-300 hover:text-white" href="/crawlers">Краулеры</a>
+1 -1
View File
@@ -20,7 +20,7 @@
hx-trigger="submit, change delay:600ms from:select, keyup delay:500ms from:input[name='q']">
<input type="text" name="q" value="{{ q }}" class="input input-sm w-56 max-w-full" placeholder="поиск…">
<select name="status" class="select select-sm w-48 max-w-full">
{% for val, label in [('', 'Все'), ('new', '💎 Новые'), ('rejected', '🗑 Отклонённые'), ('published', '✅ Опубл.')] %}
{% for val, label in [('', 'Все'), ('new', '💎 Новые'), ('queued', '🗓 В плане'), ('rejected', '🗑 Отклонённые'), ('published', '✅ Опубл.')] %}
<option value="{{ val }}" {% if status == val %}selected{% endif %}>{{ label }}{% if counts.get(val) %} ({{ counts[val] }}){% endif %}</option>
{% endfor %}
</select>
+111
View File
@@ -0,0 +1,111 @@
{% extends "base.html" %}
{% block page %}plan{% endblock %}
{% block title %}План публикаций{% endblock %}
{% block content %}
<div class="flex items-center justify-between mb-3 gap-2 flex-wrap">
<h4 class="text-xl font-semibold m-0">🗓 План публикаций</h4>
<div class="text-neutral-500 text-sm">
Сейчас: {{ now }} ({{ tz_name }})
{% if live %}
· <span class="badge badge-success">живой режим</span>
{% else %}
· <span class="badge badge-warning">сухой прогон</span>
{% endif %}
</div>
</div>
{% if error %}
<div class="alert alert-error mb-3">❌ {{ error }}</div>
{% endif %}
{% if did %}
<div class="alert alert-success mb-3">✅ {{ did }}</div>
{% endif %}
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4">
<div class="card card-outline bg-white">
<div class="card-content">
<h6 class="card-title text-neutral-500 text-sm">В очереди</h6>
<h3 class="text-2xl font-semibold m-0">{{ rows|length }}</h3>
</div>
</div>
<div class="card card-outline bg-white">
<div class="card-content">
<h6 class="card-title text-neutral-500 text-sm">Следующая публикация</h6>
<h3 class="text-2xl font-semibold m-0">{{ next_slot or '—' }}</h3>
</div>
</div>
<div class="card card-outline bg-white">
<div class="card-content">
<h6 class="card-title text-neutral-500 text-sm">Слотов в сутки</h6>
<h3 class="text-2xl font-semibold m-0">{{ slots|length }}</h3>
<small class="text-neutral-500">{{ slots|join(' · ') }}</small>
</div>
</div>
</div>
{% if ahead > 1 %}
<div class="alert alert-warning mb-4">
⏳ Очередь заполнена примерно на {{ ahead }} дн. — новые посты уедут далеко вперёд.
Часть можно снять из плана (✖) и вернуть в «Отобранные».
</div>
{% endif %}
<div class="card card-outline bg-white">
<div class="border-b border-neutral-200 px-4 py-2 font-bold">Очередь ({{ rows|length }})</div>
<div class="overflow-x-auto">
<table class="table table-sm">
<thead class="bg-neutral-100">
<tr>
<th class="w-40">Время публикации</th>
<th>Пост</th>
<th class="text-right">Действия</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td class="whitespace-nowrap font-medium">{{ r.scheduled_at }}</td>
<td class="min-w-0">
<div class="flex items-center gap-1 flex-wrap">
<a href="/selected?selected={{ r.id }}" class="no-underline font-semibold">#{{ r.id }}</a>
{% if r.direction %}<span class="badge badge-neutral">{{ r.direction }}</span>{% endif %}
{% if r.source_name %}<span class="text-neutral-500 text-sm">{{ r.source_name }}</span>{% endif %}
</div>
<div class="text-neutral-500 text-sm truncate" style="max-width: 60ch;">
{{ (r.rewritten_text or r.text or '')[:90] }}
</div>
</td>
<td class="text-right whitespace-nowrap">
<form method="post" action="/plan/{{ r.id }}/up" class="inline-block">
<button class="btn btn-sm btn-outline" title="Выше в очереди"{% if loop.first %} disabled{% endif %}>⬆</button>
</form>
<form method="post" action="/plan/{{ r.id }}/down" class="inline-block">
<button class="btn btn-sm btn-outline" title="Ниже в очереди"{% if loop.last %} disabled{% endif %}>⬇</button>
</form>
<form method="post" action="/plan/{{ r.id }}/publish-now" class="inline-block"
onsubmit="return confirm('Опубликовать #{{ r.id }} сейчас, мимо расписания?')">
<button class="btn btn-sm btn-success" title="Опубликовать сейчас">🚀</button>
</form>
<form method="post" action="/plan/{{ r.id }}/dequeue" class="inline-block"
onsubmit="return confirm('Снять #{{ r.id }} с плана и вернуть в «Отобранные»?')">
<button class="btn btn-sm btn-outline text-red-600" title="Убрать из плана">✖</button>
</form>
</td>
</tr>
{% else %}
<tr><td colspan="3">
<div class="alert alert-info">Очередь пуста — отметь посты в «⭐ Отобранные» и нажми «🗓 В очередь».</div>
</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="text-neutral-500 text-sm mt-3">
Один пост на слот. Публикатор запускается каждые 5 минут и берёт самый ранний просроченный пост —
не больше одного за запуск, чтобы в канале не было пачек.
{% if not live %}<br><b>Сухой прогон:</b> посты не уходят в канал, публикатор пишет только в logs/publish-queue.log.
Живой режим включается флагом PUBLISH_QUEUE_LIVE=1.{% endif %}
</div>
{% endblock %}
+7
View File
@@ -79,6 +79,13 @@
<button class="btn btn-outline text-blue-600" type="submit" title="Сгенерировать черновик своего поста через модель — затем отредактируйте в поле справа">✍️ Переписать</button>
</form>
{% endif %}
{% if selected.status != 'published' %}
<form method="post" action="/posts/{{ selected.id }}/enqueue"
hx-post="/posts/{{ selected.id }}/enqueue" hx-swap="none">
{{ hid }}
<button class="btn btn-info" type="submit" title="Поставить в план публикации — пост уйдёт из «Отобранных» в очередь и будет опубликован в ближайший свободный слот">🗓 В очередь</button>
</form>
{% endif %}
{% if selected.status != 'rejected' and selected.status != 'published' %}
<form method="post" action="/posts/{{ selected.id }}/reject"
hx-post="/posts/{{ selected.id }}/reject" hx-swap="none">