ORE Studio 0.0.4
Loading...
Searching...
No Matches
reflectors.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#ifndef ORES_SCHEDULER_RFL_REFLECTORS_HPP
21#define ORES_SCHEDULER_RFL_REFLECTORS_HPP
22
23#include <rfl.hpp>
24#include "ores.scheduler.api/domain/cron_expression.hpp"
25#include "ores.scheduler.api/domain/job_status.hpp"
26
27namespace rfl {
28
35template<>
36struct Reflector<ores::scheduler::domain::cron_expression> {
37 using ReflType = std::string;
38
39 static ores::scheduler::domain::cron_expression to(const ReflType& str) {
41 if (!result) {
42 throw std::runtime_error("Invalid cron expression: " + result.error());
43 }
44 return *result;
45 }
46
47 static ReflType from(const ores::scheduler::domain::cron_expression& v) {
48 return v.to_string();
49 }
50};
51
57template<>
58struct Reflector<ores::scheduler::domain::job_status> {
59 using ReflType = std::string;
60
61 static ores::scheduler::domain::job_status to(const ReflType& str) {
62 if (str == "starting") return ores::scheduler::domain::job_status::starting;
63 if (str == "succeeded") return ores::scheduler::domain::job_status::succeeded;
64 if (str == "failed") return ores::scheduler::domain::job_status::failed;
65 throw std::runtime_error("Invalid job_status: " + str);
66 }
67
68 static ReflType from(const ores::scheduler::domain::job_status& v) {
69 switch (v) {
70 case ores::scheduler::domain::job_status::starting: return "starting";
71 case ores::scheduler::domain::job_status::succeeded: return "succeeded";
72 case ores::scheduler::domain::job_status::failed: return "failed";
73 }
74 throw std::logic_error("Unhandled ores::scheduler::domain::job_status enum value.");
75 }
76};
77
78}
79
80#endif
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition image.hpp:29
Strongly-typed, validated cron expression.
Definition cron_expression.hpp:44
const std::string & to_string() const noexcept
The validated cron string, suitable for pg_cron's cron.schedule().
Definition cron_expression.cpp:61
static std::expected< cron_expression, std::string > from_string(std::string_view expr)
Parse and validate a cron expression string.
Definition cron_expression.cpp:48