Class: Clockwork::ManagerWithDatabaseTasks
- Defined in:
- lib/clockwork/manager_with_database_tasks.rb
Constant Summary collapse
- SECOND_TO_RUN_DATABASE_SYNC_AT =
0
Instance Attribute Summary
Attributes inherited from Manager
Instance Method Summary collapse
-
#initialize ⇒ ManagerWithDatabaseTasks
constructor
A new instance of ManagerWithDatabaseTasks.
- #sync_database_tasks(options = {}, &block) ⇒ Object
Methods inherited from Manager
#configure, #default_configuration, #error_handler, #every, #fire_callbacks, #handle_error, #handler, #log, #log_error, #on, #run, #thread_available?, #tick
Constructor Details
#initialize ⇒ ManagerWithDatabaseTasks
Returns a new instance of ManagerWithDatabaseTasks.
15 16 17 18 19 |
# File 'lib/clockwork/manager_with_database_tasks.rb', line 15 def initialize super @events_from_database = [] @next_sync_database_tasks_identifier = 0 end |
Instance Method Details
#sync_database_tasks(options = {}, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/clockwork/manager_with_database_tasks.rb', line 21 def sync_database_tasks(={}, &block) [:model, :every].each do |option| raise ArgumentError.new("requires :#{option} option") unless .include?(option) end raise ArgumentError.new(":every must be greater or equal to 1.minute") if [:every] < 1.minute model = [:model] frequency = [:every] sync_task_id = get_sync_task_id # Prevent database tasks from running in same cycle as the database sync, # as this can lead to the same task being run twice = { :if => lambda { |t| t.sec == SECOND_TO_RUN_DATABASE_SYNC_AT } } # create event that syncs clockwork events with database events every frequency, "sync_database_tasks_for_model_#{model}", do reload_events_from_database sync_task_id, model, &block end end |