Sha256: cb4c11c6569442bbdac5ce0265384fb6a3e90e395e7bfdc89ff5a3bc709f7cb0

Contents?: true

Size: 937 Bytes

Versions: 5

Compression:

Stored size: 937 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|
        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

  private

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
test_track_rails_client-4.0.2 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.1 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.rc3 app/models/test_track/unsynced_assignments_notifier.rb
test_track_rails_client-4.0.0.rc2 app/models/test_track/unsynced_assignments_notifier.rb