Class: Workers::HandleChanges

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker, Sidetiq::Schedulable
Defined in:
lib/workers/handle_changes.rb

Defined Under Namespace

Classes: TrogdirAPIError

Instance Method Summary collapse

Instance Method Details

#performObject

Raises:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/workers/handle_changes.rb', line 14

def perform
  Log.info "[#{jid}] Starting job"

  response = change_syncs.start.perform
  raise TrogdirAPIError, response.parse['error'] unless response.success?

  hashes = Array(response.parse)

  # Keep processing batches until we run out
  changes_processed = if hashes.any?
    Log.info "[#{jid}] Processing #{hashes.length} changes"

    hashes.each do |hash|
      Workers::HandleChange.perform_async(hash)
    end
  end

  Log.info "[#{jid}] Finished job"

  # Run the worker again since there is probably more to process
  if changes_processed
    HandleChanges.perform_async
  end
end