Class: Kaal::SchedulerFileLoader
- Inherits:
-
Object
- Object
- Kaal::SchedulerFileLoader
- Defined in:
- lib/kaal/scheduler_file_loader.rb
Overview
Loads scheduler definitions from config/scheduler.yml and registers them.
Constant Summary collapse
- PLACEHOLDER_PATTERN =
/\{\{\s*([a-zA-Z0-9_.]+)\s*\}\}/- ALLOWED_PLACEHOLDERS =
{ 'fire_time.iso8601' => ->(ctx) { ctx.fetch(:fire_time).iso8601 }, 'fire_time.unix' => ->(ctx) { ctx.fetch(:fire_time).to_i }, 'idempotency_key' => ->(ctx) { ctx.fetch(:idempotency_key) }, 'key' => ->(ctx) { ctx.fetch(:key) } }.freeze
Constants included from SchedulerHashTransform
Kaal::SchedulerHashTransform::TO_STRING, Kaal::SchedulerHashTransform::TO_SYMBOL
Instance Method Summary collapse
-
#initialize(configuration:, definition_registry:, registry:, logger:, rails_context: Rails) ⇒ SchedulerFileLoader
constructor
A new instance of SchedulerFileLoader.
- #load ⇒ Object
Constructor Details
#initialize(configuration:, definition_registry:, registry:, logger:, rails_context: Rails) ⇒ SchedulerFileLoader
Returns a new instance of SchedulerFileLoader.
31 32 33 34 35 36 37 38 39 |
# File 'lib/kaal/scheduler_file_loader.rb', line 31 def initialize(configuration:, definition_registry:, registry:, logger:, rails_context: Rails) @configuration = configuration @definition_registry = definition_registry @registry = registry @logger = logger @rails_env = rails_context.env.to_s @rails_root = rails_context.root @placeholder_resolvers = ALLOWED_PLACEHOLDERS end |
Instance Method Details
#load ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kaal/scheduler_file_loader.rb', line 41 def load applied_job_contexts = [] path = scheduler_file_path return handle_missing_file(path) unless File.exist?(path) payload = parse_yaml(path) jobs = extract_jobs(payload) validate_unique_keys(jobs) normalized_jobs = jobs.map { |job_payload| normalize_job(job_payload) } applied_jobs = [] normalized_jobs.each do |job| applied_job_context = apply_job(**job) next unless applied_job_context applied_jobs << job applied_job_contexts << applied_job_context end applied_jobs rescue StandardError rollback_applied_jobs(applied_job_contexts) raise end |