Class: Maestrano::Connector::Rails::AllSynchronizationsJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/maestrano/connector/rails/all_synchronizations_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(name = nil, count = nil) ⇒ Object

Trigger synchronization of all active organizations



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/jobs/maestrano/connector/rails/all_synchronizations_job.rb', line 6

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