ORE Studio 0.0.4
Loading...
Searching...
No Matches
cron_scheduler.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#pragma once
21
22#include <string>
23#include <vector>
24#include <boost/uuid/uuid.hpp>
25#include "ores.database/domain/context.hpp"
26#include "ores.scheduler.api/domain/job_definition.hpp"
27#include "ores.scheduler.api/domain/job_instance.hpp"
28#include "ores.scheduler.core/repository/job_definition_repository.hpp"
29#include "ores.scheduler.core/repository/job_instance_repository.hpp"
30
31namespace ores::scheduler::service {
32
48class cron_scheduler final {
49public:
51
52 explicit cron_scheduler(context ctx);
53
54 // -------------------------------------------------------------------------
55 // Registration phase
56 // -------------------------------------------------------------------------
57
66 const std::string& change_reason_code,
67 const std::string& change_commentary);
68
75 void unschedule(const boost::uuids::uuid& job_definition_id,
76 const std::string& modified_by,
77 const std::string& change_reason_code,
78 const std::string& change_commentary);
79
80 // -------------------------------------------------------------------------
81 // Observation phase
82 // -------------------------------------------------------------------------
83
87 [[nodiscard]] std::vector<domain::job_definition> get_all_definitions();
88
94 [[nodiscard]] std::vector<domain::job_instance>
95 get_job_history(const boost::uuids::uuid& job_definition_id,
96 std::size_t limit = 100);
97
98private:
99 context ctx_;
102};
103
104} // namespace ores::scheduler::service
Context for the operations on a postgres database.
Definition context.hpp:47
Persistent plan for an in-process scheduled job.
Definition job_definition.hpp:38
Reads and writes job definitions to data storage.
Definition job_definition_repository.hpp:37
Reads and writes job instance records to ores_scheduler_job_instances_tbl.
Definition job_instance_repository.hpp:38
Coordinator for OreStudio in-process job scheduling.
Definition cron_scheduler.hpp:48
domain::job_definition schedule(domain::job_definition def, const std::string &change_reason_code, const std::string &change_commentary)
Persist a job definition and mark it as active.
Definition cron_scheduler.cpp:45
std::vector< domain::job_definition > get_all_definitions()
All job definitions visible to the current tenant+party context.
Definition cron_scheduler.cpp:87
void unschedule(const boost::uuids::uuid &job_definition_id, const std::string &modified_by, const std::string &change_reason_code, const std::string &change_commentary)
Mark a job as inactive (paused).
Definition cron_scheduler.cpp:57
std::vector< domain::job_instance > get_job_history(const boost::uuids::uuid &job_definition_id, std::size_t limit=100)
Execution history for a specific job, newest-first.
Definition cron_scheduler.cpp:92