Class: Aeternitas::Pollable::Dsl
- Inherits:
-
Object
- Object
- Aeternitas::Pollable::Dsl
- Defined in:
- lib/aeternitas/pollable/dsl.rb
Overview
DSL wrapper to conveniently configure pollables
Instance Method Summary collapse
-
#after_polling(method) ⇒ Object
Configures a method that will be run after every successful poll.
-
#before_polling(method) ⇒ Object
Configures a method that will be run before every poll.
-
#deactivate_on(*error_class) ⇒ Object
Configure errors that will cause the pollable instance to be deactivated immediately during poll.
-
#guard_key(key) ⇒ Object
Configure the guard key.
-
#guard_options(options) ⇒ Object
Configure the guard.
-
#ignore_error(*error_class) ⇒ Object
Configure errors that will be wrapped in Error::Ignored.
-
#initialize(configuration, &block) ⇒ Dsl
constructor
Create a new DSL instance and configure the configuration with the given block.
-
#polling_frequency(frequency) ⇒ Object
Configures the polling frequency.
-
#queue(queue) ⇒ Object
Configure the Sidekiq queue into which the instance’s poll jobs will be enqueued.
-
#sleep_on_guard_locked(switch) ⇒ Object
Configure the behaviour of poll jobs if a lock can’t be acquired.
Constructor Details
#initialize(configuration, &block) ⇒ Dsl
Create a new DSL instance and configure the configuration with the given block
8 9 10 11 |
# File 'lib/aeternitas/pollable/dsl.rb', line 8 def initialize(configuration, &block) @configuration = configuration instance_eval(&block) end |
Instance Method Details
#after_polling(method) ⇒ Object
Configures a method that will be run after every successful poll
57 58 59 60 61 62 63 |
# File 'lib/aeternitas/pollable/dsl.rb', line 57 def after_polling(method) if method.is_a?(Symbol) @configuration.after_polling << ->(pollable) { pollable.send(method) } else @configuration.after_polling << method end end |
#before_polling(method) ⇒ Object
Configures a method that will be run before every poll
40 41 42 43 44 45 46 |
# File 'lib/aeternitas/pollable/dsl.rb', line 40 def before_polling(method) if method.is_a?(Symbol) @configuration.before_polling << ->(pollable) { pollable.send(method) } else @configuration.before_polling << method end end |
#deactivate_on(*error_class) ⇒ Object
Configure errors that will cause the pollable instance to be deactivated immediately during poll.
68 69 70 |
# File 'lib/aeternitas/pollable/dsl.rb', line 68 def deactivate_on(*error_class) @configuration.deactivation_errors |= error_class end |
#guard_key(key) ⇒ Object
Configure the guard key. This can be either a fixed String, a method reference or a block
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/aeternitas/pollable/dsl.rb', line 95 def guard_key(key) @configuration.[:key] = case key when Symbol ->(obj) { return obj.send(key) } when Proc key else ->(obj) { return key.to_s } end end |
#guard_options(options) ⇒ Object
Configure the guard.
110 111 112 |
# File 'lib/aeternitas/pollable/dsl.rb', line 110 def () @configuration..merge!() end |
#ignore_error(*error_class) ⇒ Object
Configure errors that will be wrapped in Error::Ignored. Use this to group exceptions which should be ignored in your exception tracker.
76 77 78 |
# File 'lib/aeternitas/pollable/dsl.rb', line 76 def ignore_error(*error_class) @configuration.ignored_errors |= error_class end |
#polling_frequency(frequency) ⇒ Object
allow custom methods via reference
Configures the polling frequency. This can be either the name of a Aeternitas::PollingFrequency or a lambda that receives a pollable instance and returns a DateTime
23 24 25 26 27 28 29 |
# File 'lib/aeternitas/pollable/dsl.rb', line 23 def polling_frequency(frequency) if frequency.is_a?(Symbol) @configuration.polling_frequency = Aeternitas::PollingFrequency.by_name(frequency) else @configuration.polling_frequency = frequency end end |
#queue(queue) ⇒ Object
Configure the Sidekiq queue into which the instance’s poll jobs will be enqueued.
82 83 84 |
# File 'lib/aeternitas/pollable/dsl.rb', line 82 def queue(queue) @configuration.queue = queue end |
#sleep_on_guard_locked(switch) ⇒ Object
Configure the behaviour of poll jobs if a lock can’t be acquired. When set to true poll jobs (and effectively the Sidekiq worker thread) will sleep until the lock is released if the lock could not be acquired.
118 119 120 |
# File 'lib/aeternitas/pollable/dsl.rb', line 118 def sleep_on_guard_locked(switch) @configuration.sleep_on_guard_locked = switch end |