Class: Kaal::EnabledEntryEnumerator
- Inherits:
-
Object
- Object
- Kaal::EnabledEntryEnumerator
- Defined in:
- lib/kaal/core/enabled_entry_enumerator.rb,
sig/kaal/core/enabled_entry_enumerator.rbs
Overview
Enumerates scheduler entries from persisted definitions or the in-memory registry.
Instance Method Summary collapse
- #build_entry(definition) ⇒ nil, Kaal::rbs_any
- #each {|arg0| ... } ⇒ Kaal::rbs_any
-
#initialize(configuration:, registry:, definition_registry_provider: -> { Kaal.definition_registry }) ⇒ EnabledEntryEnumerator
constructor
A new instance of EnabledEntryEnumerator.
- #resolve_entries ⇒ Kaal::rbs_any
- #yield_registry_entries {|arg0| ... } ⇒ Kaal::rbs_any
Constructor Details
#initialize(configuration:, registry:, definition_registry_provider: -> { Kaal.definition_registry }) ⇒ EnabledEntryEnumerator
Returns a new instance of EnabledEntryEnumerator.
10 11 12 13 14 |
# File 'lib/kaal/core/enabled_entry_enumerator.rb', line 10 def initialize(configuration:, registry:, definition_registry_provider: -> { Kaal.definition_registry }) @configuration = configuration @registry = registry @definition_registry_provider = definition_registry_provider end |
Instance Method Details
#build_entry(definition) ⇒ nil, Kaal::rbs_any
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kaal/core/enabled_entry_enumerator.rb', line 40 def build_entry(definition) key = definition[:key] callback_entry = @registry.find(key) unless callback_entry&.enqueue @configuration.logger&.warn("No enqueue callback registered for definition '#{key}', skipping") return nil end Registry::Entry.new(key: key, cron: definition[:cron], enqueue: callback_entry.enqueue).freeze end |
#each {|arg0| ... } ⇒ Kaal::rbs_any
16 17 18 19 20 21 |
# File 'lib/kaal/core/enabled_entry_enumerator.rb', line 16 def each(&) resolve_entries.each(&) rescue StandardError => e @configuration.logger&.warn("Failed to iterate enabled definitions: #{e.message}") yield_registry_entries(&) end |
#resolve_entries ⇒ Kaal::rbs_any
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kaal/core/enabled_entry_enumerator.rb', line 29 def resolve_entries registry_entries = @registry.to_enum definition_registry = @definition_registry_provider.call return registry_entries unless definition_registry definitions = definition_registry.enabled_definitions || [] return registry_entries if definitions.empty? && definition_registry.all_definitions.to_a.empty? definitions.filter_map { |definition| build_entry(definition) } end |
#yield_registry_entries {|arg0| ... } ⇒ Kaal::rbs_any
25 26 27 |
# File 'lib/kaal/core/enabled_entry_enumerator.rb', line 25 def yield_registry_entries(&) @registry.each(&) end |