Class: Insika::Schedule

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 = message_of(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

#cronObject (readonly)

Returns the value of attribute cron.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def cron
  @cron
end

#enabledObject (readonly)

Returns the value of attribute enabled.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def enabled
  @enabled
end

#everyObject (readonly)

Returns the value of attribute every.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def every
  @every
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def message
  @message
end

#overridesObject (readonly)

Returns the value of attribute overrides.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def overrides
  @overrides
end

#session_idObject (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_modeObject (readonly)

Returns the value of attribute session_mode.



21
22
23
# File 'lib/insika/schedule.rb', line 21

def session_mode
  @session_mode
end

#tzObject (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

Returns:

  • (Boolean)


54
# File 'lib/insika/schedule.rb', line 54

def cron? = !@cron.nil?

#every?Boolean

Returns:

  • (Boolean)


55
# File 'lib/insika/schedule.rb', line 55

def every? = !@every.nil?

#fixed_session?Boolean

Returns:

  • (Boolean)


56
# File 'lib/insika/schedule.rb', line 56

def fixed_session? = @session_mode == "fixed"

#to_hObject



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