Class: CopayNotifications::ParseNewStatementsJob

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

Constant Summary collapse

JOB_INTERVAL =

time (in seconds) between scheduling batch of jobs

Settings.mcp.notifications.job_interval
BATCH_SIZE =

number of jobs to perform at next interval

Settings.mcp.notifications.batch_size

Instance Method Summary collapse

Instance Method Details

#perform(statements_json_byte) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/sidekiq/copay_notifications/parse_new_statements_job.rb', line 14

def perform(statements_json_byte)
  StatsD.increment('api.copay_notifications.json_file.total')
  # Decode and parse large json file (~60-90k objects)
  statements_json = Oj.load(Base64.decode64(statements_json_byte))
  unique_statements = statements_json.uniq { |statement| statement['veteranIdentifier'] }

  unique_statements.each_with_index do |statement, index|
    # For every BATCH_SIZE jobs, enqueue the next BATCH_SIZE amount of jobs JOB_INTERVAL seconds later
    CopayNotifications::NewStatementNotificationJob.perform_in(
      JOB_INTERVAL * (index / BATCH_SIZE), statement
    )
  end
end