Move schedule_jobs method to the Geo::BaseSchedulerWorker

parent d7922319
......@@ -105,6 +105,17 @@ module Geo
@scheduled_jobs = @scheduled_jobs.zip(status).map { |(job, completed)| job if completed }.compact
end
def schedule_jobs
num_to_schedule = [max_capacity - scheduled_job_ids.size, pending_resources.size].min
return unless resources_remain?
num_to_schedule.times do
job = schedule_job(*pending_resources.shift)
scheduled_jobs << job if job&.fetch(:job_id).present?
end
end
def scheduled_job_ids
scheduled_jobs.map { |data| data[:job_id] }
end
......
......@@ -7,19 +7,10 @@ class GeoFileDownloadDispatchWorker < Geo::BaseSchedulerWorker
LEASE_KEY
end
def schedule_jobs
num_to_schedule = [max_capacity - scheduled_job_ids.size, pending_resources.size].min
def schedule_job(object_db_id, object_type)
job_id = GeoFileDownloadWorker.perform_async(object_type, object_db_id)
return unless resources_remain?
num_to_schedule.times do
object_db_id, object_type = pending_resources.shift
job_id = GeoFileDownloadWorker.perform_async(object_type, object_db_id)
if job_id
@scheduled_jobs << { id: object_db_id, type: object_type, job_id: job_id }
end
end
{ id: object_db_id, type: object_type, job_id: job_id } if job_id
end
def load_pending_resources
......
......@@ -13,17 +13,10 @@ class GeoRepositorySyncWorker < Geo::BaseSchedulerWorker
MAX_CAPACITY
end
def schedule_jobs
num_to_schedule = [max_capacity - scheduled_job_ids.size, pending_resources.size].min
def schedule_job(project_id)
job_id = Geo::ProjectSyncWorker.perform_in(BACKOFF_DELAY, project_id, Time.now)
return unless resources_remain?
num_to_schedule.times do
project_id = pending_resources.shift
job_id = Geo::ProjectSyncWorker.perform_in(BACKOFF_DELAY, project_id, Time.now)
scheduled_jobs << { id: project_id, job_id: job_id } if job_id
end
{ id: project_id, job_id: job_id } if job_id
end
def load_pending_resources
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment