Skip to content

Commit

Permalink
fix: add statement_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 13, 2024
1 parent 69fd5b5 commit 6733cd6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions app/workers/generate_udt_hourly_statistic_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ class GenerateUdtHourlyStatisticWorker
include Sidekiq::Job

def perform
statistic_attributes = []
udt_types = %i[xudt xudt_compatible spore_cell did_cell]
created_at_unixtimestamp = to_be_counted_date.beginning_of_day.to_i
ActiveRecord::Base.connection.execute("SET statement_timeout = 0")
Udt.where(udt_type: udt_types, published: true).find_each do |udt|
statistic_attributes << {
udt_id: udt.id,
amount: calc_amount(udt),
ckb_transactions_count: calc_ckb_transactions_count(udt),
holders_count: calc_holders_count(udt),
created_at_unixtimestamp:,
}
end

if statistic_attributes.present?
DailyStatisticGenerator.upsert_all(
statistic_attributes,
puts "Generating statistics for #{udt.id}"
RgbppHourlyStatistic.upsert(
{
udt_id: udt.id,
amount: calc_amount(udt),
ckb_transactions_count: calc_ckb_transactions_count(udt),
holders_count: calc_holders_count(udt),
created_at_unixtimestamp:,
},
unique_by: %i[udt_id created_at_unixtimestamp],
)
end
ActiveRecord::Base.connection.execute("RESET statement_timeout")
rescue StandardError => e
Rails.logger.error "Error occurred during GenerateUdtHourlyStatistic error: #{e.message}"
end
Expand Down

0 comments on commit 6733cd6

Please sign in to comment.