Module: Karafka::Pro::RecurringTasks
- Defined in:
- lib/karafka/pro/recurring_tasks.rb,
lib/karafka/pro/recurring_tasks/task.rb,
lib/karafka/pro/recurring_tasks/errors.rb,
lib/karafka/pro/recurring_tasks/matcher.rb,
lib/karafka/pro/recurring_tasks/consumer.rb,
lib/karafka/pro/recurring_tasks/executor.rb,
lib/karafka/pro/recurring_tasks/listener.rb,
lib/karafka/pro/recurring_tasks/schedule.rb,
lib/karafka/pro/recurring_tasks/dispatcher.rb,
lib/karafka/pro/recurring_tasks/serializer.rb,
lib/karafka/pro/recurring_tasks/deserializer.rb,
lib/karafka/pro/recurring_tasks/setup/config.rb,
lib/karafka/pro/recurring_tasks/contracts/task.rb,
lib/karafka/pro/recurring_tasks/contracts/config.rb
Overview
Recurring tasks functionality
Defined Under Namespace
Modules: Contracts, Errors, Setup Classes: Consumer, Deserializer, Dispatcher, Executor, Listener, Matcher, Schedule, Serializer, Task
Class Method Summary collapse
-
.define(version = '1.0.0', &block) ⇒ Object
Simplified API for schedules definitions and validates the tasks data.
- .post_setup(config) ⇒ Object
-
.pre_setup(config) ⇒ Object
Sets up additional config scope, validations and other things.
-
.schedule ⇒ Schedule?
Current defined schedule or nil if not defined.
Class Method Details
.define(version = '1.0.0', &block) ⇒ Object
Simplified API for schedules definitions and validates the tasks data
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/karafka/pro/recurring_tasks.rb', line 35 def define(version = '1.0.0', &block) @schedule = Schedule.new(version: version) @schedule.instance_exec(&block) @schedule.each do |task| Contracts::Task.new.validate!(task.to_h) end @schedule end |
.post_setup(config) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/karafka/pro/recurring_tasks.rb', line 69 def post_setup(config) RecurringTasks::Contracts::Config.new.validate!(config.to_h) # Published after task is successfully executed Karafka.monitor.notifications_bus.register_event('recurring_tasks.task.executed') # Initialize empty dummy schedule, so we always have one and so we do not have to # deal with a case where there is no schedule RecurringTasks.schedule # User can disable logging of executions, in which case we don't track them return unless Karafka::App.config.recurring_tasks.logging Karafka.monitor.subscribe(Listener.new) end |
.pre_setup(config) ⇒ Object
Sets up additional config scope, validations and other things
61 62 63 64 65 66 |
# File 'lib/karafka/pro/recurring_tasks.rb', line 61 def pre_setup(config) # Expand the config with this feature specific stuff config.instance_eval do setting(:recurring_tasks, default: Setup::Config.config) end end |
.schedule ⇒ Schedule?
Returns current defined schedule or nil if not defined.
20 21 22 |
# File 'lib/karafka/pro/recurring_tasks.rb', line 20 def schedule @schedule || define('0.0.0') {} end |