#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 #include #include #include "store/sqlite.hpp" #include "velox_proto.hpp" namespace velox::daemon::store { class Queues { public: explicit Queues(Db& db) : db_(db) {} DbResult> list(); // nullopt (not an error) if no queue has this id. DbResult> 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 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 set_schedule(std::string_view queue_id, const std::optional& 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 reorder(std::string_view queue_id, const std::vector& 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 upsert(velox::proto::Queue queue); private: Db& db_; }; } // namespace velox::daemon::store