Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
151cccb6
Commit
151cccb6
authored
Jul 13, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common constants to the Geo::BaseSchedulerWorker
parent
3e7632cf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
45 deletions
+30
-45
app/workers/geo/base_scheduler_worker.rb
app/workers/geo/base_scheduler_worker.rb
+21
-0
app/workers/geo_file_download_dispatch_worker.rb
app/workers/geo_file_download_dispatch_worker.rb
+3
-23
app/workers/geo_repository_sync_worker.rb
app/workers/geo_repository_sync_worker.rb
+4
-20
spec/workers/geo_file_download_dispatch_worker_spec.rb
spec/workers/geo_file_download_dispatch_worker_spec.rb
+2
-2
No files found.
app/workers/geo/base_scheduler_worker.rb
View file @
151cccb6
...
...
@@ -3,6 +3,11 @@ module Geo
include
Sidekiq
::
Worker
include
CronjobQueue
DB_RETRIEVE_BATCH_SIZE
=
1000
LEASE_TIMEOUT
=
10
.
minutes
MAX_CAPACITY
=
10
RUN_TIME
=
60
.
minutes
.
to_i
def
initialize
@pending_resources
=
[]
@scheduled_jobs
=
[]
...
...
@@ -53,6 +58,22 @@ module Geo
private
def
db_retrieve_batch_size
DB_RETRIEVE_BATCH_SIZE
end
def
lease_timeout
LEASE_TIMEOUT
end
def
max_capacity
MAX_CAPACITY
end
def
run_time
RUN_TIME
end
def
reload_queue?
@pending_resources
.
size
<
max_capacity
end
...
...
app/workers/geo_file_download_dispatch_worker.rb
View file @
151cccb6
class
GeoFileDownloadDispatchWorker
<
Geo
::
BaseSchedulerWorker
LEASE_KEY
=
'geo_file_download_dispatch_worker'
.
freeze
LEASE_TIMEOUT
=
10
.
minutes
DB_RETRIEVE_BATCH_SIZE
=
1000
MAX_CAPACITY
=
10
RUN_TIME
=
60
.
minutes
.
to_i
private
...
...
@@ -11,24 +7,8 @@ class GeoFileDownloadDispatchWorker < Geo::BaseSchedulerWorker
LEASE_KEY
end
def
lease_timeout
LEASE_TIMEOUT
end
def
db_retrieve_batch_size
DB_RETRIEVE_BATCH_SIZE
end
def
max_capacity
MAX_CAPACITY
end
def
run_time
RUN_TIME
end
def
schedule_jobs
num_to_schedule
=
[
MAX_CAPACITY
-
scheduled_job_ids
.
size
,
@pending_resources
.
size
].
min
num_to_schedule
=
[
max_capacity
-
scheduled_job_ids
.
size
,
@pending_resources
.
size
].
min
return
unless
resources_remain?
...
...
@@ -43,8 +23,8 @@ class GeoFileDownloadDispatchWorker < Geo::BaseSchedulerWorker
end
def
load_pending_resources
lfs_object_ids
=
find_lfs_object_ids
(
DB_RETRIEVE_BATCH_SIZE
)
objects_ids
=
find_object_ids
(
DB_RETRIEVE_BATCH_SIZE
)
lfs_object_ids
=
find_lfs_object_ids
(
db_retrieve_batch_size
)
objects_ids
=
find_object_ids
(
db_retrieve_batch_size
)
@pending_resources
=
interleave
(
lfs_object_ids
,
objects_ids
)
end
...
...
app/workers/geo_repository_sync_worker.rb
View file @
151cccb6
class
GeoRepositorySyncWorker
<
Geo
::
BaseSchedulerWorker
LEASE_KEY
=
'geo_repository_sync_worker'
.
freeze
LEASE_TIMEOUT
=
10
.
minutes
DB_RETRIEVE_BATCH_SIZE
=
1000
MAX_CAPACITY
=
25
RUN_TIME
=
60
.
minutes
.
to_i
BACKOFF_DELAY
=
5
.
minutes
MAX_CAPACITY
=
25
private
...
...
@@ -13,24 +9,12 @@ class GeoRepositorySyncWorker < Geo::BaseSchedulerWorker
LEASE_KEY
end
def
lease_timeout
LEASE_TIMEOUT
end
def
db_retrieve_batch_size
DB_RETRIEVE_BATCH_SIZE
end
def
max_capacity
MAX_CAPACITY
end
def
run_time
RUN_TIME
end
def
schedule_jobs
num_to_schedule
=
[
MAX_CAPACITY
-
scheduled_job_ids
.
size
,
@pending_resources
.
size
].
min
num_to_schedule
=
[
max_capacity
-
scheduled_job_ids
.
size
,
@pending_resources
.
size
].
min
return
unless
resources_remain?
...
...
@@ -52,14 +36,14 @@ class GeoRepositorySyncWorker < Geo::BaseSchedulerWorker
def
find_project_ids_not_synced
Project
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
DB_RETRIEVE_BATCH_SIZE
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
end
def
find_project_ids_updated_recently
Geo
::
ProjectRegistry
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
DB_RETRIEVE_BATCH_SIZE
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:project_id
)
end
end
spec/workers/geo_file_download_dispatch_worker_spec.rb
View file @
151cccb6
...
...
@@ -50,8 +50,8 @@ describe GeoFileDownloadDispatchWorker do
# 1. A total of 8 files in the queue, and we can load a maximimum of 5 and send 2 at a time.
# 2. We send 2, wait for 1 to finish, and then send again.
it
'attempts to load a new batch without pending downloads'
do
stub_const
(
'Geo
FileDownloadDispatch
Worker::DB_RETRIEVE_BATCH_SIZE'
,
5
)
stub_const
(
'Geo
FileDownloadDispatch
Worker::MAX_CAPACITY'
,
2
)
stub_const
(
'Geo
::BaseScheduler
Worker::DB_RETRIEVE_BATCH_SIZE'
,
5
)
stub_const
(
'Geo
::BaseScheduler
Worker::MAX_CAPACITY'
,
2
)
avatar
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/dk.png'
))
create_list
(
:lfs_object
,
2
,
:with_file
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment