Sha256: 85684eb2e31ed95ea74c483badcb4d158ee2a5aabee3eaca7592a8375e44da4d

Contents?: true

Size: 737 Bytes

Versions: 7

Compression:

Stored size: 737 Bytes

Contents

require_relative '../database_events'

module Clockwork

  module DatabaseEvents

    class Synchronizer

      def self.setup(options={}, &block_to_perform_on_event_trigger)
        model_class = options.fetch(:model) { raise KeyError, ":model must be set to the model class" }
        every = options.fetch(:every) { raise KeyError, ":every must be set to the database sync frequency" }

        event_store = EventStore.new(block_to_perform_on_event_trigger)

        # create event that syncs clockwork events with events coming from database-backed model
        Clockwork.manager.every every, "sync_database_events_for_model_#{model_class}" do
          event_store.update(model_class.all)
        end
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clockwork-2.0.4 lib/clockwork/database_events/synchronizer.rb
clockwork-2.0.3 lib/clockwork/database_events/synchronizer.rb
clockwork-2.0.2 lib/clockwork/database_events/synchronizer.rb
clockwork-2.0.1 lib/clockwork/database_events/synchronizer.rb
clockwork-1.3.1 lib/clockwork/database_events/synchronizer.rb
clockwork-1.3.0 lib/clockwork/database_events/synchronizer.rb
clockwork-2.0.0 lib/clockwork/database_events/synchronizer.rb