Class: Insika::Schedule
- Inherits:
-
Object
- Object
- Insika::Schedule
- Defined in:
- lib/insika/schedule.rb
Overview
the parsed recurring-schedule declaration of ONE agent — the ONLY shape the engine accepts, shared by the ScheduleEngine, the doctor and the Studio. Pure value object (the followup-policy precedent).
One schedule: a name, a trigger (cron OR every, never both), a
timezone for cron materialization, the synthetic inbound message, a
session mode (a fresh session per run, or a standing one), per-run
overrides (turn_timeout / max_tool_calls / model) and an enabled flag.
parse returns nil on a malformed hash (the engine SKIPS, the doctor
explains, the Studio refuses); parse! raises Insika::ValidationError
naming the exact defect.
Constant Summary collapse
- SESSION_MODES =
%w[new fixed].freeze
- OVERRIDE_KEYS =
%w[turn_timeout max_tool_calls model].freeze
- ID_RE =
/\A[a-z][a-z0-9_-]*\z/
Instance Attribute Summary collapse
-
#cron ⇒ Object
readonly
Returns the value of attribute cron.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#every ⇒ Object
readonly
Returns the value of attribute every.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#session_mode ⇒ Object
readonly
Returns the value of attribute session_mode.
-
#tz ⇒ Object
readonly
Returns the value of attribute tz.
Class Method Summary collapse
Instance Method Summary collapse
- #cron? ⇒ Boolean
- #every? ⇒ Boolean
- #fixed_session? ⇒ Boolean
-
#initialize(hash) ⇒ Schedule
constructor
A new instance of Schedule.
- #to_h ⇒ Object
Constructor Details
#initialize(hash) ⇒ Schedule
Returns a new instance of Schedule.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/insika/schedule.rb', line 34 def initialize(hash) raise Insika::ValidationError, "schedule: declaration must be a Hash" unless hash.is_a?(Hash) h = hash.transform_keys(&:to_s) @id = id_of(h) @every = every_of(h) @cron = cron_of(h) if @cron.nil? && @every.nil? raise Insika::ValidationError, "schedule '#{@id}': a trigger is required — declare cron or every" end @tz = tz_of(h) @message = (h) @session_mode = session_mode_of(h) @session_id = session_id_of(h) @overrides = overrides_of(h) @enabled = h.key?("enabled") ? h["enabled"] == true : true freeze end |
Instance Attribute Details
#cron ⇒ Object (readonly)
Returns the value of attribute cron.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def cron @cron end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def enabled @enabled end |
#every ⇒ Object (readonly)
Returns the value of attribute every.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def every @every end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def id @id end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def @message end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def overrides @overrides end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def session_id @session_id end |
#session_mode ⇒ Object (readonly)
Returns the value of attribute session_mode.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def session_mode @session_mode end |
#tz ⇒ Object (readonly)
Returns the value of attribute tz.
21 22 23 |
# File 'lib/insika/schedule.rb', line 21 def tz @tz end |
Class Method Details
.parse(hash) ⇒ Object
24 25 26 27 28 |
# File 'lib/insika/schedule.rb', line 24 def self.parse(hash) new(hash) rescue Insika::ValidationError nil end |
.parse!(hash) ⇒ Object
30 31 32 |
# File 'lib/insika/schedule.rb', line 30 def self.parse!(hash) new(hash) end |
Instance Method Details
#cron? ⇒ Boolean
54 |
# File 'lib/insika/schedule.rb', line 54 def cron? = !@cron.nil? |
#every? ⇒ Boolean
55 |
# File 'lib/insika/schedule.rb', line 55 def every? = !@every.nil? |
#fixed_session? ⇒ Boolean
56 |
# File 'lib/insika/schedule.rb', line 56 def fixed_session? = @session_mode == "fixed" |
#to_h ⇒ Object
58 59 60 61 62 63 |
# File 'lib/insika/schedule.rb', line 58 def to_h { "id" => @id, "cron" => @cron, "every" => @every, "tz" => @tz, "message" => @message, "session_mode" => @session_mode, "session_id" => @session_id, "overrides" => @overrides, "enabled" => @enabled }.compact end |