ReUseX
0.0.5
3D Point Cloud Processing for Building Reuse
Toggle main menu visibility
Loading...
Searching...
No Matches
JobStore.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2
//
3
// SPDX-License-Identifier: GPL-3.0-or-later
4
5
#pragma once
6
7
// Where job records live (spec 2026-10-08, phase S2).
8
//
9
// The JobScheduler keeps the *live* state of a job — its place in the queue,
10
// its cancel token, its progress counters — in memory, because none of that
11
// means anything once the process is gone. What it hands to an IJobStore is
12
// the job's *record* at each state transition (submitted, started, finished),
13
// so a store backed by a database sees a handful of writes per job, never a
14
// stream of progress ticks.
15
//
16
// `ruxd --local` uses InMemoryJobStore. The multi-user server (phase S3)
17
// backs the same interface with its Postgres `jobs` table.
18
//
19
// Records are grouped by *queue*: one queue per project (a ruxd case). Job
20
// ids are GUIDs, unique across queues, but every lookup names the queue too,
21
// so one case can never read another case's job by guessing its id.
22
23
#include "reusex/pipeline/job_types.hpp"
24
25
#include <cstddef>
26
#include <memory>
27
#include <optional>
28
#include <string>
29
#include <string_view>
30
#include <vector>
31
32
namespace
reusex::pipeline
{
33
35
class
IJobStore
{
36
public
:
37
virtual
~IJobStore
() =
default
;
38
41
virtual
void
save
(std::string_view queue,
const
JobRecord
&record) = 0;
42
45
virtual
std::optional<JobRecord>
find
(std::string_view queue,
46
std::string_view
id
)
const
= 0;
47
49
virtual
std::vector<JobRecord>
list
(std::string_view queue)
const
= 0;
50
53
virtual
void
forget
(std::string_view queue) = 0;
54
};
55
61
class
InMemoryJobStore
final :
public
IJobStore
{
62
public
:
63
explicit
InMemoryJobStore
(std::size_t max_terminal_jobs = 256);
64
~InMemoryJobStore
()
override
;
65
66
void
save
(std::string_view queue,
const
JobRecord
&record)
override
;
67
std::optional<JobRecord>
find
(std::string_view queue,
68
std::string_view
id
)
const override
;
69
std::vector<JobRecord>
list
(std::string_view queue)
const override
;
70
void
forget
(std::string_view queue)
override
;
71
72
private
:
73
class
Impl;
74
std::unique_ptr<Impl> impl_;
75
};
76
77
}
// namespace reusex::pipeline
reusex::pipeline::IJobStore
Persistence for job records. Implementations must be thread-safe.
Definition
JobStore.hpp:35
reusex::pipeline::IJobStore::list
virtual std::vector< JobRecord > list(std::string_view queue) const =0
Every retained record of queue, most recently submitted first.
reusex::pipeline::IJobStore::find
virtual std::optional< JobRecord > find(std::string_view queue, std::string_view id) const =0
One record, or nullopt when id is unknown in queue (or was evicted by the store's retention policy).
reusex::pipeline::IJobStore::forget
virtual void forget(std::string_view queue)=0
Drop every record of queue (its case was deleted, and a new case may reuse the key).
reusex::pipeline::IJobStore::save
virtual void save(std::string_view queue, const JobRecord &record)=0
Insert record under queue, or replace the record with the same id.
reusex::pipeline::IJobStore::~IJobStore
virtual ~IJobStore()=default
reusex::pipeline::InMemoryJobStore::list
std::vector< JobRecord > list(std::string_view queue) const override
Every retained record of queue, most recently submitted first.
reusex::pipeline::InMemoryJobStore::save
void save(std::string_view queue, const JobRecord &record) override
Insert record under queue, or replace the record with the same id.
reusex::pipeline::InMemoryJobStore::find
std::optional< JobRecord > find(std::string_view queue, std::string_view id) const override
One record, or nullopt when id is unknown in queue (or was evicted by the store's retention policy).
reusex::pipeline::InMemoryJobStore::forget
void forget(std::string_view queue) override
Drop every record of queue (its case was deleted, and a new case may reuse the key).
reusex::pipeline::InMemoryJobStore::InMemoryJobStore
InMemoryJobStore(std::size_t max_terminal_jobs=256)
reusex::pipeline::InMemoryJobStore::~InMemoryJobStore
~InMemoryJobStore() override
reusex::pipeline
Definition
job_types.hpp:24
reusex::pipeline::JobRecord
A job as reported by the runner. Snapshot; never a live view.
Definition
job_types.hpp:53
libs
reusex
include
pipeline
JobStore.hpp
Generated by
1.18.0