chore(service): maintenance tasks refreshing geocoding
This commit is contained in:
parent
578f19b000
commit
4ce8e75001
1 changed files with 34 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Maintenance
|
||||||
|
class UpdateServiceEtablissementInfosTask < MaintenanceTasks::Task
|
||||||
|
# No more 20 geocoding by 10 seconds window
|
||||||
|
THROTTLE_LIMIT = 20
|
||||||
|
THROTTLE_PERIOD = 10.seconds
|
||||||
|
|
||||||
|
@@request_count = 0
|
||||||
|
@@period_start = Time.current
|
||||||
|
|
||||||
|
throttle_on(backoff: THROTTLE_LIMIT) do
|
||||||
|
if Time.current - @@period_start > THROTTLE_PERIOD
|
||||||
|
@@request_count = 0
|
||||||
|
@@period_start = Time.current
|
||||||
|
end
|
||||||
|
|
||||||
|
@@request_count += 1
|
||||||
|
@@request_count > THROTTLE_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection
|
||||||
|
Service.where.not(siret: nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(service)
|
||||||
|
APIEntreprise::ServiceJob.perform_now(service.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def count
|
||||||
|
collection.count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue