ORE Studio 0.0.4
Loading...
Searching...
No Matches
job_instance_repository.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 <chrono>
23#include <cstdint>
24#include <optional>
25#include <string>
26#include <vector>
27#include <boost/uuid/uuid.hpp>
28#include "ores.logging/make_logger.hpp"
29#include "ores.database/domain/context.hpp"
30#include "ores.scheduler.api/domain/job_instance.hpp"
31#include "ores.scheduler.api/domain/job_status.hpp"
32
33namespace ores::scheduler::repository {
34
39private:
40 inline static std::string_view logger_name =
41 "ores.scheduler.repository.job_instance_repository";
42
43 [[nodiscard]] static auto& lg() {
44 using namespace ores::logging;
45 static auto instance = make_logger(logger_name);
46 return instance;
47 }
48
49public:
51
55 std::int64_t write_started(context ctx, const domain::job_instance& inst);
56
60 void write_completed(context ctx, std::int64_t id,
61 const std::chrono::system_clock::time_point& triggered_at,
62 domain::job_status status, const std::string& error = "");
63
67 std::vector<domain::job_instance> read_latest(context ctx,
68 const boost::uuids::uuid& job_definition_id, std::size_t limit = 100);
69
73 std::optional<std::chrono::system_clock::time_point> last_run_at(
74 context ctx, const boost::uuids::uuid& job_definition_id);
75};
76
77} // namespace ores::scheduler::repository
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
A record of a single in-process job execution.
Definition job_instance.hpp:37
Reads and writes job instance records to ores_scheduler_job_instances_tbl.
Definition job_instance_repository.hpp:38
std::int64_t write_started(context ctx, const domain::job_instance &inst)
Inserts a new job instance row with status='started' and returns the new id.
Definition job_instance_repository.cpp:51
std::vector< domain::job_instance > read_latest(context ctx, const boost::uuids::uuid &job_definition_id, std::size_t limit=100)
Returns the most recent job instances for a given job_definition_id.
Definition job_instance_repository.cpp:117
std::optional< std::chrono::system_clock::time_point > last_run_at(context ctx, const boost::uuids::uuid &job_definition_id)
Returns the triggered_at of the most recent run for a job definition, if any.
Definition job_instance_repository.cpp:183
void write_completed(context ctx, std::int64_t id, const std::chrono::system_clock::time_point &triggered_at, domain::job_status status, const std::string &error="")
Updates completed_at, duration_ms, status and error_message for the given id.
Definition job_instance_repository.cpp:89