Class: Kaal::Definitions::RegistrationService
- Inherits:
-
Object
- Object
- Kaal::Definitions::RegistrationService
- Includes:
- RegisterConflictSupport
- Defined in:
- lib/kaal/definitions/registration_service.rb
Overview
Registers code-defined jobs while preserving persisted definition state.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#definition_registry ⇒ Object
readonly
Returns the value of attribute definition_registry.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #call(key:, cron:, enqueue:) ⇒ Object
-
#initialize(configuration:, definition_registry:, registry:) ⇒ RegistrationService
constructor
A new instance of RegistrationService.
Constructor Details
#initialize(configuration:, definition_registry:, registry:) ⇒ RegistrationService
Returns a new instance of RegistrationService.
15 16 17 18 19 |
# File 'lib/kaal/definitions/registration_service.rb', line 15 def initialize(configuration:, definition_registry:, registry:) @configuration = configuration @definition_registry = definition_registry @registry = registry end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/kaal/definitions/registration_service.rb', line 13 def configuration @configuration end |
#definition_registry ⇒ Object (readonly)
Returns the value of attribute definition_registry.
13 14 15 |
# File 'lib/kaal/definitions/registration_service.rb', line 13 def definition_registry @definition_registry end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/kaal/definitions/registration_service.rb', line 13 def registry @registry end |
Instance Method Details
#call(key:, cron:, enqueue:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kaal/definitions/registration_service.rb', line 21 def call(key:, cron:, enqueue:) existing_definition = @definition_registry.find_definition(key) existing_entry = @registry.find(key) if existing_entry conflict_result = resolve_register_conflict( key: key, cron: cron, enqueue: enqueue, existing_definition: existing_definition, existing_entry: existing_entry ) return conflict_result if conflict_result raise RegistryError, "Key '#{key}' is already registered" end persisted_attributes = { enabled: true, source: 'code', metadata: {} }.merge(Definition::AttributeHelpers.persisted_definition_attributes(existing_definition)) @definition_registry.upsert_definition(key: key, cron: cron, **persisted_attributes) with_registered_definition_rollback(key, existing_definition) do @registry.add(key: key, cron: cron, enqueue: enqueue) end end |