rules.list/rules.upsert: new store/rules.{hpp,cpp} (list in priority order; apply()
upserts+removes atomically, generating an id when absent, per the schema's own "never
leaves the table in a half-valid state"). Found and fixed along the way: migration
0001's rules table had no column for Rule.name at all — every rules.list/.upsert call
failed outright ("no such column: name"), unit tests included, since :memory: migrates
through the same path. Migration 0004 adds it.
queue.reorder: new store::Queues::reorder — taskIds must be an exact permutation of
the queue's current membership (compared as sorted sets) or nothing is written and
-32602 names the queue; a valid permutation rewrites every member's queue_position in
one transaction.
schedule.get/schedule.set: a thin wrapper over the queues.schedule column (already
read since D3b, never independently settable). nextRunAt is deliberately left unset —
computing it needs the same local-time, DST-aware window logic
sched/schedule_window.hpp's window_open() only has half of; called out rather than
approximated, and the field is optional.
limiter.get/limiter.set: backed by the same downloads.speedLimitEnabled/
downloads.speedLimitBps settings keys D9 already wired — one bag of truth, not two.
The new part is reaching the engine: EnginePort/TaskActionPort gain
set_global_speed_limit(bps) (0 = unlimited, TokenBucket's own convention), wired to
Engine::rate_limiter().set_global_limit(). Pushed live on every limiter.set *and* on
Scheduler::reload_config() so a limit from a previous run isn't silently unlimited
again after a restart. applyToRunning is accepted but has no lever to pull
differently — a single shared global bucket has no "next task only" variant. Also
found, not chased further: the schema's "globalBps:0 with enabled:true means 'stop
everything'" is the opposite of what TokenBucket does with rate_bps==0 (unlimited) —
a real discrepancy, but the schema says the GUI must not offer that combination.
download.update: "moving saveDir or filename moves the file on disk in the same
operation" — resolved and root-checked like download.add's destination, then the
.veloxpart/.veloxpart.meta pair (or the finished file, if complete) is moved via
rename, falling back to copy+remove across filesystems, only when the resolved
location actually differs. categoryId/queueId(appended to the new queue's run
order)/description/segments/bufferBytes/checksum apply through new
store::Tasks::apply_update.
download.refreshUrl: same async server-layer special-case as download.probe (a real
network round trip, same 30s deadline). Re-probes, flags contentChanged only when
size or validator are both known and actually differ, persists the new URL and probe
result, and swaps the URL on a live engine handle via a newly-widened
EnginePort::refresh_url (now takes headers too, matching DownloadHandle's real
signature — the seam had silently dropped them).
Found and documented, not fixed: the generated parser collapses "field absent" and
"field explicitly null" to the same nullopt for every optional<T> patch field
(DownloadUpdateParamsPatch, Settings) — both schemas document "an explicit null
clears the field" but neither handler can act on it because the wire distinction is
already gone by the time either sees the parsed struct. A generator-level gap
(PROTO's), not something to hand-route around locally.
Verified against real veloxd + tools/testserver: rules create/list, limiter.set
takes effect and reads back, schedule.set/get round-trips, queue.reorder against real
membership (and rejects a non-permutation), download.update renames+recategorizes a
task, download.refreshUrl swaps a paused task's URL and reports contentChanged
correctly. Full ctest: 55/55 (excluding the pre-existing, unrelated conformance
failure noted two commits back).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GRDjHGgpYmMoPE2UFbe7pP
53 lines
2.2 KiB
C++
53 lines
2.2 KiB
C++
#pragma once
|
|
|
|
// Read access to the `queues` table, projected onto proto::Queue. taskIds is derived from
|
|
// `tasks` (queue_id = this queue, ordered by queue_position), not stored on the queue row
|
|
// — membership changes through download.update / queue.reorder, per Queue's own schema
|
|
// note that a queue.upsert payload's taskIds is ignored.
|
|
|
|
#include <optional>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#include "store/sqlite.hpp"
|
|
#include "velox_proto.hpp"
|
|
|
|
namespace velox::daemon::store {
|
|
|
|
class Queues {
|
|
public:
|
|
explicit Queues(Db& db) : db_(db) {}
|
|
|
|
DbResult<std::vector<velox::proto::Queue>> list();
|
|
|
|
// nullopt (not an error) if no queue has this id.
|
|
DbResult<std::optional<velox::proto::Queue>> get(std::string_view queue_id);
|
|
|
|
// 'running' or 'stopped' (Queue.schema.json / the state column's CHECK). false if the
|
|
// id doesn't exist.
|
|
DbResult<bool> set_state(std::string_view queue_id, std::string_view state);
|
|
|
|
// schedule.set: nullopt clears it (NULL = manual control, per the schema's own
|
|
// words). false if the queue doesn't exist.
|
|
DbResult<bool> set_schedule(std::string_view queue_id,
|
|
const std::optional<velox::proto::Schedule>& schedule);
|
|
|
|
// queue.reorder: `task_ids` must be an exact permutation of the queue's current
|
|
// membership (the schema's own words — "anything else is -32602 rather than a
|
|
// partial reorder, so a stale drag from an out-of-date view cannot quietly reshuffle
|
|
// the queue"). false (no write at all) if it isn't; true and queue_position rewritten
|
|
// to match `task_ids`'s order if it is.
|
|
DbResult<bool> reorder(std::string_view queue_id, const std::vector<std::string>& task_ids);
|
|
|
|
// "Omit queueId to create" (queue.upsert's own words) — an empty id generates one.
|
|
// taskIds is ignored (membership changes only through download.update / queue.reorder,
|
|
// per the schema's own note); a create defaults to 'stopped', a replace keeps the
|
|
// queue's current run state (queue.upsert edits config, not run state).
|
|
DbResult<velox::proto::Queue> upsert(velox::proto::Queue queue);
|
|
|
|
private:
|
|
Db& db_;
|
|
};
|
|
|
|
} // namespace velox::daemon::store
|