mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Batch upsert security prices on sync
This commit is contained in:
parent
ab2cec55e7
commit
7605b0221d
1 changed files with 15 additions and 1 deletions
|
@ -63,7 +63,21 @@ module Security::Provided
|
|||
is_invalid
|
||||
end
|
||||
|
||||
Security::Price.upsert_all(valid_prices, unique_by: %i[security_id date currency])
|
||||
valid_prices.each_slice(100) do |batch|
|
||||
retries ||= 0
|
||||
|
||||
begin
|
||||
Security::Price.upsert_all(batch, unique_by: %i[security_id date currency])
|
||||
rescue => e
|
||||
if retries < 3
|
||||
retries += 1
|
||||
sleep(1)
|
||||
retry
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_or_fetch_price(date: Date.current, cache: true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue