PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
job_manager.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
18#pragma once
19
23
24#include <atomic>
25#include <chrono>
26#include <condition_variable>
27#include <future>
28#include <memory>
29#include <mutex>
30#include <queue>
31#include <shared_mutex>
32#include <string>
33#include <string_view>
34#include <thread>
35#include <vector>
36
37// Forward declarations
39class job_repository;
40}
41
43
44// Forward declaration
46
47// =============================================================================
48// Job Manager
49// =============================================================================
50
94public:
95 // =========================================================================
96 // Construction / Destruction
97 // =========================================================================
98
106 explicit job_manager(
107 std::shared_ptr<storage::job_repository> repo,
108 std::shared_ptr<remote_node_manager> node_manager,
109 std::shared_ptr<di::ILogger> logger = nullptr);
110
119 explicit job_manager(
121 std::shared_ptr<storage::job_repository> repo,
122 std::shared_ptr<remote_node_manager> node_manager,
123 std::shared_ptr<di::ILogger> logger = nullptr);
124
128 ~job_manager();
129
130 // Non-copyable, non-movable (due to internal threading)
131 job_manager(const job_manager&) = delete;
132 auto operator=(const job_manager&) -> job_manager& = delete;
134 auto operator=(job_manager&&) -> job_manager& = delete;
135
136 // =========================================================================
137 // Job Creation
138 // =========================================================================
139
151 [[nodiscard]] auto create_retrieve_job(
152 std::string_view source_node_id,
153 std::string_view study_uid,
154 std::optional<std::string_view> series_uid = std::nullopt,
155 job_priority priority = job_priority::normal) -> std::string;
156
167 [[nodiscard]] auto create_store_job(
168 std::string_view destination_node_id,
169 const std::vector<std::string>& instance_uids,
170 job_priority priority = job_priority::normal) -> std::string;
171
183 [[nodiscard]] auto create_query_job(
184 std::string_view node_id,
185 std::string_view query_level,
186 const std::unordered_map<std::string, std::string>& query_keys,
187 job_priority priority = job_priority::normal) -> std::string;
188
199 [[nodiscard]] auto create_sync_job(
200 std::string_view source_node_id,
201 std::optional<std::string_view> patient_id = std::nullopt,
202 job_priority priority = job_priority::low) -> std::string;
203
214 [[nodiscard]] auto create_prefetch_job(
215 std::string_view source_node_id,
216 std::string_view patient_id,
217 job_priority priority = job_priority::low) -> std::string;
218
219 // =========================================================================
220 // Job Control
221 // =========================================================================
222
231 [[nodiscard]] auto start_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
232
239 [[nodiscard]] auto pause_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
240
247 [[nodiscard]] auto resume_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
248
257 [[nodiscard]] auto cancel_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
258
267 [[nodiscard]] auto retry_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
268
277 [[nodiscard]] auto delete_job(std::string_view job_id) -> kcenon::pacs::VoidResult;
278
279 // =========================================================================
280 // Job Queries
281 // =========================================================================
282
289 [[nodiscard]] auto get_job(std::string_view job_id) const
290 -> std::optional<job_record>;
291
301 [[nodiscard]] auto list_jobs(
302 std::optional<job_status> status = std::nullopt,
303 std::optional<job_type> type = std::nullopt,
304 size_t limit = 100,
305 size_t offset = 0) const -> std::vector<job_record>;
306
315 [[nodiscard]] auto list_jobs_by_node(std::string_view node_id) const
316 -> std::vector<job_record>;
317
318 // =========================================================================
319 // Progress Monitoring
320 // =========================================================================
321
328 [[nodiscard]] auto get_progress(std::string_view job_id) const -> job_progress;
329
339
349
350 // =========================================================================
351 // Wait for Completion
352 // =========================================================================
353
362 [[nodiscard]] auto wait_for_completion(std::string_view job_id)
363 -> std::future<job_record>;
364
365 // =========================================================================
366 // Worker Management
367 // =========================================================================
368
375 void start_workers();
376
383 void stop_workers();
384
390 [[nodiscard]] auto is_running() const noexcept -> bool;
391
392 // =========================================================================
393 // Statistics
394 // =========================================================================
395
401 [[nodiscard]] auto active_jobs() const -> size_t;
402
408 [[nodiscard]] auto pending_jobs() const -> size_t;
409
415 [[nodiscard]] auto completed_jobs_today() const -> size_t;
416
422 [[nodiscard]] auto failed_jobs_today() const -> size_t;
423
424 // =========================================================================
425 // Configuration
426 // =========================================================================
427
433 [[nodiscard]] auto config() const noexcept -> const job_manager_config&;
434
435private:
436 // =========================================================================
437 // Private Implementation
438 // =========================================================================
439
440 struct impl;
441 std::unique_ptr<impl> impl_;
442};
443
444} // namespace kcenon::pacs::client
auto pending_jobs() const -> size_t
Get number of pending jobs.
void set_progress_callback(job_progress_callback callback)
Set the progress callback.
auto is_running() const noexcept -> bool
Check if workers are running.
auto delete_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Delete a job.
auto create_prefetch_job(std::string_view source_node_id, std::string_view patient_id, job_priority priority=job_priority::low) -> std::string
Create a prefetch job.
auto cancel_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Cancel a job.
auto create_retrieve_job(std::string_view source_node_id, std::string_view study_uid, std::optional< std::string_view > series_uid=std::nullopt, job_priority priority=job_priority::normal) -> std::string
Create a retrieve job (C-MOVE/C-GET)
void start_workers()
Start the worker threads.
auto pause_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Pause a running or queued job.
auto completed_jobs_today() const -> size_t
Get number of jobs completed today.
auto config() const noexcept -> const job_manager_config &
Get current configuration.
auto resume_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Resume a paused job.
job_manager(job_manager &&)=delete
auto list_jobs_by_node(std::string_view node_id) const -> std::vector< job_record >
List jobs by node ID.
auto create_store_job(std::string_view destination_node_id, const std::vector< std::string > &instance_uids, job_priority priority=job_priority::normal) -> std::string
Create a store job (C-STORE)
job_manager(std::shared_ptr< storage::job_repository > repo, std::shared_ptr< remote_node_manager > node_manager, std::shared_ptr< di::ILogger > logger=nullptr)
Construct a job manager with default configuration.
std::unique_ptr< impl > impl_
auto create_sync_job(std::string_view source_node_id, std::optional< std::string_view > patient_id=std::nullopt, job_priority priority=job_priority::low) -> std::string
Create a sync job.
auto create_query_job(std::string_view node_id, std::string_view query_level, const std::unordered_map< std::string, std::string > &query_keys, job_priority priority=job_priority::normal) -> std::string
Create a query job (C-FIND)
job_manager(const job_manager &)=delete
auto operator=(job_manager &&) -> job_manager &=delete
auto list_jobs(std::optional< job_status > status=std::nullopt, std::optional< job_type > type=std::nullopt, size_t limit=100, size_t offset=0) const -> std::vector< job_record >
List jobs with optional filters.
auto wait_for_completion(std::string_view job_id) -> std::future< job_record >
Wait for a job to complete.
auto active_jobs() const -> size_t
Get number of active (running) jobs.
~job_manager()
Destructor - stops workers if running.
void set_completion_callback(job_completion_callback callback)
Set the completion callback.
auto get_job(std::string_view job_id) const -> std::optional< job_record >
Get a job by ID.
auto operator=(const job_manager &) -> job_manager &=delete
auto start_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Start a pending job.
auto failed_jobs_today() const -> size_t
Get number of jobs failed today.
auto retry_job(std::string_view job_id) -> kcenon::pacs::VoidResult
Retry a failed job.
void stop_workers()
Stop the worker threads.
Repository for job persistence (legacy SQLite interface)
Logger interface for dependency injection.
Job types and structures for asynchronous DICOM operations.
std::function< void( const std::string &job_id, const job_progress &progress)> job_progress_callback
Callback for job progress updates.
Definition job_types.h:385
std::function< void( const std::string &job_id, const job_record &record)> job_completion_callback
Callback for job completion.
Definition job_types.h:395
job_priority
Priority level for job execution.
Definition job_types.h:154
@ low
Background operations.
Result<T> type aliases and helpers for PACS system.
Configuration for the job manager.
Definition job_types.h:406
Progress tracking for a job.
Definition job_types.h:211
Complete job record with all metadata.
Definition job_types.h:255