Sha256: bc34249386d9a3b1e3b518b429ca934e92d9a36a09cba156fa27822d41ba5e41

Contents?: true

Size: 787 Bytes

Versions: 2

Compression:

Stored size: 787 Bytes

Contents

module Maestrano::Connector::Rails
  class AllSynchronizationsJob < ::ActiveJob::Base
    queue_as :default

    # Trigger synchronization of all active organizations
    def perform(name = nil, count = nil)
      active_organizations = Maestrano::Connector::Rails::Organization
                             .where.not(oauth_provider: nil, encrypted_oauth_token: nil)
                             .select { |o| [true, 1].include?(o.sync_enabled) }

      return true if active_organizations.count.zero?

      time_span_seconds = (3600 / active_organizations.count).to_i
      active_organizations.each_with_index do |organization, i|
        Maestrano::Connector::Rails::SynchronizationJob.set(wait: time_span_seconds * i).perform_later(organization.id, {})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maestrano-connector-rails-2.3.4 app/jobs/maestrano/connector/rails/all_synchronizations_job.rb
maestrano-connector-rails-2.3.3 app/jobs/maestrano/connector/rails/all_synchronizations_job.rb