Class: Form526FailureStateSnapshotJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/form526_failure_state_snapshot_job.rb

Overview

Log information about Form526Submission state to populate an admin facing Datadog dashboard

Constant Summary collapse

STATSD_PREFIX =
'form526.state.snapshot'

Instance Method Summary collapse

Instance Method Details

#load_snapshot_stateObject



36
37
38
39
40
41
42
# File 'app/sidekiq/form526_failure_state_snapshot_job.rb', line 36

def load_snapshot_state
  {
    total_awaiting_backup_status: Form526Submission.pending_backup.pluck(:id).sort,
    total_incomplete_type: Form526Submission.incomplete_type.pluck(:id).sort,
    total_failure_type: Form526Submission.failure_type.pluck(:id).sort
  }
end

#performObject



10
11
12
13
14
15
16
# File 'app/sidekiq/form526_failure_state_snapshot_job.rb', line 10

def perform
  write_failure_snapshot
rescue => e
  Rails.logger.error('Error logging 526 state snapshot',
                     class: self.class.name,
                     message: e.try(:message))
end

#snapshot_stateObject



32
33
34
# File 'app/sidekiq/form526_failure_state_snapshot_job.rb', line 32

def snapshot_state
  @snapshot_state ||= load_snapshot_state
end

#state_as_countsObject



24
25
26
27
28
29
30
# File 'app/sidekiq/form526_failure_state_snapshot_job.rb', line 24

def state_as_counts
  @state_as_counts ||= {}.tap do |abbreviation|
    snapshot_state.each do |dp, ids|
      abbreviation[:"#{dp}_count"] = ids.count
    end
  end
end

#write_failure_snapshotObject



18
19
20
21
22
# File 'app/sidekiq/form526_failure_state_snapshot_job.rb', line 18

def write_failure_snapshot
  state_as_counts.each do |description, count|
    StatsD.gauge("#{STATSD_PREFIX}.#{description}", count)
  end
end