Sha256: 288e925732318fe0d2e934c79e1a27d1e4fca87bfe61022d373d6435684a15d0

Contents?: true

Size: 971 Bytes

Versions: 37

Compression:

Stored size: 971 Bytes

Contents

class TestTrack::UnsyncedAssignmentsNotifier
  attr_reader :visitor_id, :assignments

  def initialize(opts)
    @visitor_id = opts.delete(:visitor_id)
    @assignments = opts.delete(:assignments)

    %w(visitor_id assignments).each do |param_name|
      raise "#{param_name} must be present" if send(param_name).blank?
    end
    raise "unknown opts: #{opts.keys.to_sentence}" if opts.present?
  end

  def notify
    assignments.each do |assignment|
      build_notify_assignment_job(assignment).tap do |job|
        begin
          job.perform
        rescue *TestTrack::SERVER_ERRORS => e
          Rails.logger.error "TestTrack failed to notify unsynced assignments, retrying. #{e}"
          Delayed::Job.enqueue(build_notify_assignment_job(assignment))
        end
      end
    end
  end

  private

  def build_notify_assignment_job(assignment)
    TestTrack::NotifyAssignmentJob.new(
      visitor_id: visitor_id,
      assignment: assignment
    )
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
test_track_rails_client-4.0.0.alpha35 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha34 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha33 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha32 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha31 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha30 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha29 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha28 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha27 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha26 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha25 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha24 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha23 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha22 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha21 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha20 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha19 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha18 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha17 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.alpha16 app/models/test_track/unsynced_assignments_notifier.rb