Class: Kaal::SchedulerFileLoader
- Inherits:
-
Object
- Object
- Kaal::SchedulerFileLoader
- Defined in:
- lib/kaal/scheduler_file/loader.rb,
lib/kaal/scheduler_file/job_applier.rb,
lib/kaal/scheduler_file/helper_bundle.rb,
lib/kaal/scheduler_file/job_normalizer.rb,
lib/kaal/scheduler_file/payload_loader.rb
Overview
Loads scheduler definitions from config/scheduler.yml and registers them.
Defined Under Namespace
Classes: HelperBundle, JobApplier, JobNormalizer, PayloadLoader
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
Instance Method Summary collapse
-
#initialize(configuration:, definition_registry:, registry:, logger:, runtime_context: RuntimeContext.default) ⇒ SchedulerFileLoader
constructor
A new instance of SchedulerFileLoader.
- #load ⇒ Object
Methods included from Kaal::Support::HashTools
constantize, deep_dup, deep_merge, duplicable?, stringify_keys, symbolize_keys
Constructor Details
#initialize(configuration:, definition_registry:, registry:, logger:, runtime_context: RuntimeContext.default) ⇒ SchedulerFileLoader
Returns a new instance of SchedulerFileLoader.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kaal/scheduler_file/loader.rb', line 31 def initialize( configuration:, definition_registry:, registry:, logger:, runtime_context: RuntimeContext.default ) @configuration = configuration @definition_registry = definition_registry @registry = registry @logger = logger @runtime_context = runtime_context @placeholder_resolvers = ALLOWED_PLACEHOLDERS end |
Instance Method Details
#load ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kaal/scheduler_file/loader.rb', line 46 def load applied_job_contexts = [] path, payload = payload_loader.load return handle_missing_file(path) unless payload 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 |