Module: Xeno::Schedules
- Defined in:
- lib/xeno/schedules.rb
Overview
Compiles agent/schedules/*.md into Solid Queue recurring entries. There is no polling dispatcher: the queue's own recurring machinery fires ScheduleJob.
Only keys under the managed prefix are touched, so hand-written entries survive a sync. User schedules are written for every environment except development, where the dispatch endpoint triggers them by name. The reaper entry is runtime infrastructure and goes into every environment.
Constant Summary collapse
- MANAGED_PREFIX =
:nodoc:
"xeno_".freeze
- REAPER_KEY =
"#{MANAGED_PREFIX}runtime_reaper".freeze
Class Method Summary collapse
- .reaper_entry ⇒ Object
- .sync!(definition: Xeno.definition, path: Rails.root.join("config", "recurring.yml")) ⇒ Object
Class Method Details
.reaper_entry ⇒ Object
44 45 46 |
# File 'lib/xeno/schedules.rb', line 44 def reaper_entry { "class" => "Xeno::ReaperJob", "schedule" => "every minute" } end |
.sync!(definition: Xeno.definition, path: Rails.root.join("config", "recurring.yml")) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xeno/schedules.rb', line 19 def sync!(definition: Xeno.definition, path: Rails.root.join("config", "recurring.yml")) existing = File.exist?(path) ? (YAML.safe_load_file(path) || {}) : {} environments = (existing.keys.presence || %w[production]) | %w[development] environments.each do |env| section = (existing[env] ||= {}) section.delete_if { |key, _| key.start_with?(MANAGED_PREFIX) } unless env == "development" definition.schedules.each do |name, schedule| section["#{MANAGED_PREFIX}#{name}"] = { "class" => "Xeno::ScheduleJob", "args" => [ name ], "schedule" => schedule.cron } end end section[REAPER_KEY] = reaper_entry end File.write(path, YAML.dump(existing)) existing end |