slovensko-digital/harvester.ecosystem

View on GitHub
app/jobs/itms/sync_all_payment_claims_job.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class Itms::SyncAllPaymentClaimsJob < ItmsJob
  def perform(downloader: ItmsJob::Downloader, modified_since: latest_payment_claim_timestamp)
    json = downloader.get_json_from_href('/v2/zop/predlozene', modifiedSince: modified_since)
    json.each { |item| Itms::SyncPaymentClaimJob.perform_later(item['href']) }
  end

  def latest_payment_claim_timestamp
    [Itms::PaymentClaim.where.not(itms_updated_at: nil).order(:itms_updated_at).last&.itms_updated_at, Itms::PaymentClaim.where.not(itms_created_at: nil).order(:itms_created_at).last&.itms_created_at].max&.to_i
  end
end