Class: Form526SubmissionProcessingReportJob

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

Overview

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

Constant Summary collapse

END_DATE =
Time.zone.today.beginning_of_day
START_DATE =
END_DATE - 1.week

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date: START_DATE, end_date: END_DATE) ⇒ Form526SubmissionProcessingReportJob

Returns a new instance of Form526SubmissionProcessingReportJob.



13
14
15
16
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 13

def initialize(start_date: START_DATE, end_date: END_DATE)
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



8
9
10
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 8

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



8
9
10
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 8

def start_date
  @start_date
end

Instance Method Details

#load_timeboxed_stateObject



47
48
49
50
51
52
53
54
55
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 47

def load_timeboxed_state
  {
    timeboxed: timeboxed_submissions.pluck(:id).sort,
    timeboxed_primary_successes: timeboxed_submissions.accepted_to_primary_path.pluck(:id).sort,
    timeboxed_exhausted_primary_job: timeboxed_submissions.with_exhausted_primary_jobs.pluck(:id).sort,
    timeboxed_exhausted_backup_job: timeboxed_submissions.with_exhausted_backup_jobs.pluck(:id).sort,
    timeboxed_incomplete_type: timeboxed_submissions.incomplete_type.pluck(:id).sort
  }
end

#performObject



18
19
20
21
22
23
24
25
26
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 18

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

#state_as_countsObject



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

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

#sub_arelObject



57
58
59
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 57

def sub_arel
  @sub_arel ||= Form526Submission.arel_table
end

#sub_arel_created_atObject



67
68
69
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 67

def sub_arel_created_at
  sub_arel[:created_at]
end

#timeboxed_stateObject



43
44
45
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 43

def timeboxed_state
  @timeboxed_state ||= load_timeboxed_state
end

#timeboxed_submissionsObject



61
62
63
64
65
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 61

def timeboxed_submissions
  @timeboxed_submissions ||= Form526Submission
                             .where(sub_arel_created_at.gt(start_date))
                             .where(sub_arel_created_at.lt(end_date))
end

#write_as_logObject



28
29
30
31
32
33
# File 'app/sidekiq/form526_submission_processing_report_job.rb', line 28

def write_as_log
  Rails.logger.info('Form 526 State Data',
                    state_log: state_as_counts,
                    start_date:,
                    end_date:)
end