PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::workflow::cron_schedule Struct Reference

Cron-like schedule expression. More...

#include <task_scheduler_config.h>

Collaboration diagram for kcenon::pacs::workflow::cron_schedule:
Collaboration graph

Public Member Functions

auto to_string () const -> std::string
 Convert to cron expression string.
 
auto is_valid () const noexcept -> bool
 Check if the schedule is valid.
 

Static Public Member Functions

static auto every_minutes (int n) -> cron_schedule
 Create a schedule that runs every N minutes.
 
static auto every_hours (int n) -> cron_schedule
 Create a schedule that runs every N hours.
 
static auto daily_at (int hour, int minute=0) -> cron_schedule
 Create a daily schedule at specific time.
 
static auto weekly_on (int day_of_week, int hour=0, int minute=0) -> cron_schedule
 Create a weekly schedule.
 
static auto parse (const std::string &expr) -> cron_schedule
 Parse a cron expression string.
 

Public Attributes

std::string minute {"*"}
 Minute (0-59, or "*")
 
std::string hour {"*"}
 Hour (0-23, or "*")
 
std::string day_of_month {"*"}
 Day of month (1-31, or "*")
 
std::string month {"*"}
 Month (1-12, or "*")
 
std::string day_of_week {"*"}
 Day of week (0-6, Sunday=0, or "*")
 

Detailed Description

Cron-like schedule expression.

Supports cron-style scheduling with minute, hour, day, month, weekday. Special values: * (any), ranges (1-5), lists (1,3,5), steps (*\/5)

Definition at line 54 of file task_scheduler_config.h.

Member Function Documentation

◆ daily_at()

static auto kcenon::pacs::workflow::cron_schedule::daily_at ( int hour,
int minute = 0 ) -> cron_schedule
inlinestaticnodiscard

Create a daily schedule at specific time.

Parameters
hourHour of day (0-23)
minuteMinute of hour (0-59)

Definition at line 96 of file task_scheduler_config.h.

96 {
97 cron_schedule s;
98 s.minute = std::to_string(minute);
99 s.hour = std::to_string(hour);
100 return s;
101 }
std::string minute
Minute (0-59, or "*")
std::string hour
Hour (0-23, or "*")

References hour, and minute.

◆ every_hours()

static auto kcenon::pacs::workflow::cron_schedule::every_hours ( int n) -> cron_schedule
inlinestaticnodiscard

Create a schedule that runs every N hours.

Parameters
nHours between runs

Definition at line 84 of file task_scheduler_config.h.

84 {
85 cron_schedule s;
86 s.minute = "0";
87 s.hour = "*/" + std::to_string(n);
88 return s;
89 }

References hour, and minute.

◆ every_minutes()

static auto kcenon::pacs::workflow::cron_schedule::every_minutes ( int n) -> cron_schedule
inlinestaticnodiscard

Create a schedule that runs every N minutes.

Parameters
nMinutes between runs

Definition at line 74 of file task_scheduler_config.h.

74 {
75 cron_schedule s;
76 s.minute = "*/" + std::to_string(n);
77 return s;
78 }

References minute.

◆ is_valid()

auto kcenon::pacs::workflow::cron_schedule::is_valid ( ) const -> bool
nodiscardnoexcept

Check if the schedule is valid.

Returns
true if all fields are valid

Definition at line 58 of file task_scheduler.cpp.

58 {
59 // Basic validation - check that fields are not empty
60 return !minute.empty() && !hour.empty() && !day_of_month.empty() &&
61 !month.empty() && !day_of_week.empty();
62}
std::string month
Month (1-12, or "*")
std::string day_of_month
Day of month (1-31, or "*")
std::string day_of_week
Day of week (0-6, Sunday=0, or "*")

References day_of_month, day_of_week, hour, minute, and month.

◆ parse()

auto kcenon::pacs::workflow::cron_schedule::parse ( const std::string & expr) -> cron_schedule
staticnodiscard

Parse a cron expression string.

Parameters
exprCron expression (e.g., "0 2 * * *" for daily at 2am)
Returns
Parsed cron_schedule

Definition at line 34 of file task_scheduler.cpp.

34 {
35 cron_schedule result;
36 std::istringstream iss(expr);
37 std::vector<std::string> parts;
38 std::string part;
39
40 while (iss >> part) {
41 parts.push_back(part);
42 }
43
44 if (parts.size() >= 1) result.minute = parts[0];
45 if (parts.size() >= 2) result.hour = parts[1];
46 if (parts.size() >= 3) result.day_of_month = parts[2];
47 if (parts.size() >= 4) result.month = parts[3];
48 if (parts.size() >= 5) result.day_of_week = parts[4];
49
50 return result;
51}

References day_of_month, day_of_week, hour, minute, and month.

◆ to_string()

auto kcenon::pacs::workflow::cron_schedule::to_string ( ) const -> std::string
nodiscard

Convert to cron expression string.

Returns
Cron expression string

Definition at line 53 of file task_scheduler.cpp.

53 {
54 return minute + " " + hour + " " + day_of_month + " " + month + " " +
56}

References day_of_month, day_of_week, hour, minute, and month.

◆ weekly_on()

static auto kcenon::pacs::workflow::cron_schedule::weekly_on ( int day_of_week,
int hour = 0,
int minute = 0 ) -> cron_schedule
inlinestaticnodiscard

Create a weekly schedule.

Parameters
day_of_weekDay of week (0=Sunday, 6=Saturday)
hourHour of day
minuteMinute of hour

Definition at line 109 of file task_scheduler_config.h.

110 {
111 cron_schedule s;
112 s.minute = std::to_string(minute);
113 s.hour = std::to_string(hour);
114 s.day_of_week = std::to_string(day_of_week);
115 return s;
116 }

References day_of_week, hour, and minute.

Member Data Documentation

◆ day_of_month

std::string kcenon::pacs::workflow::cron_schedule::day_of_month {"*"}

Day of month (1-31, or "*")

Definition at line 62 of file task_scheduler_config.h.

62{"*"};

Referenced by is_valid(), parse(), and to_string().

◆ day_of_week

std::string kcenon::pacs::workflow::cron_schedule::day_of_week {"*"}

Day of week (0-6, Sunday=0, or "*")

Definition at line 68 of file task_scheduler_config.h.

68{"*"};

Referenced by is_valid(), parse(), to_string(), and weekly_on().

◆ hour

std::string kcenon::pacs::workflow::cron_schedule::hour {"*"}

Hour (0-23, or "*")

Definition at line 59 of file task_scheduler_config.h.

59{"*"};

Referenced by daily_at(), every_hours(), is_valid(), parse(), to_string(), and weekly_on().

◆ minute

std::string kcenon::pacs::workflow::cron_schedule::minute {"*"}

Minute (0-59, or "*")

Definition at line 56 of file task_scheduler_config.h.

56{"*"};

Referenced by daily_at(), every_hours(), every_minutes(), is_valid(), parse(), to_string(), and weekly_on().

◆ month

std::string kcenon::pacs::workflow::cron_schedule::month {"*"}

Month (1-12, or "*")

Definition at line 65 of file task_scheduler_config.h.

65{"*"};

Referenced by is_valid(), parse(), and to_string().


The documentation for this struct was generated from the following files: