mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 16:19:40 +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
|
is_invalid
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def find_or_fetch_price(date: Date.current, cache: true)
|
def find_or_fetch_price(date: Date.current, cache: true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue