Class: Clockwork::ManagerWithDatabaseTasks

Inherits:
Manager
  • Object
show all
Defined in:
lib/clockwork/manager_with_database_tasks.rb

Instance Attribute Summary

Attributes inherited from Manager

#config

Instance Method Summary collapse

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

#initializeManagerWithDatabaseTasks

Returns a new instance of ManagerWithDatabaseTasks.



110
111
112
113
# File 'lib/clockwork/manager_with_database_tasks.rb', line 110

def initialize
  super
  @database_event_sync_performers = []
end

Instance Method Details

#sync_database_tasks(options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/clockwork/manager_with_database_tasks.rb', line 115

def sync_database_tasks(options={}, &block)
  [:model, :every].each do |option|
    raise ArgumentError.new("requires :#{option} option") unless options.include?(option)
  end
  raise ArgumentError.new(":every must be greater or equal to 1.minute") if options[:every] < 1.minute

  sync_performer = DatabaseEventSyncPerformer.new(self, options[:model], block)
  @database_event_sync_performers << sync_performer

  # create event that syncs clockwork events with database events
  every options[:every], "sync_database_tasks_for_model_#{options[:model]}" do
    sync_performer.sync
  end
end