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
65cd7ad5
Commit
65cd7ad5
authored
Nov 04, 2020
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spread CI minute reset workers over 3 hours
parent
d402804f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
ee/app/workers/clear_shared_runners_minutes_worker.rb
ee/app/workers/clear_shared_runners_minutes_worker.rb
+10
-2
ee/spec/workers/clear_shared_runners_minutes_worker_spec.rb
ee/spec/workers/clear_shared_runners_minutes_worker_spec.rb
+6
-5
No files found.
ee/app/workers/clear_shared_runners_minutes_worker.rb
View file @
65cd7ad5
...
@@ -17,9 +17,17 @@ class ClearSharedRunnersMinutesWorker # rubocop:disable Scalability/IdempotentWo
...
@@ -17,9 +17,17 @@ class ClearSharedRunnersMinutesWorker # rubocop:disable Scalability/IdempotentWo
start_id
=
Namespace
.
minimum
(
:id
)
start_id
=
Namespace
.
minimum
(
:id
)
last_id
=
Namespace
.
maximum
(
:id
)
last_id
=
Namespace
.
maximum
(
:id
)
(
start_id
..
last_id
).
step
(
BATCH_SIZE
)
do
|
batch_start_id
|
execution_offset
=
3
.
hours
.
seconds
/
((
last_id
-
start_id
)
/
BATCH_SIZE
)
(
start_id
..
last_id
).
step
(
BATCH_SIZE
).
with_index
do
|
batch_start_id
,
batch_index
|
batch_end_id
=
batch_start_id
+
BATCH_SIZE
-
1
batch_end_id
=
batch_start_id
+
BATCH_SIZE
-
1
Ci
::
BatchResetMinutesWorker
.
perform_async
(
batch_start_id
,
batch_end_id
)
delay
=
execution_offset
*
batch_index
# #perform_in is used instead of #perform_async to spread the load
# evenly accross the first three hours of the month to avoid stressing
# the database.
Ci
::
BatchResetMinutesWorker
.
perform_in
(
delay
,
batch_start_id
,
batch_end_id
)
end
end
else
else
return
unless
try_obtain_lease
return
unless
try_obtain_lease
...
...
ee/spec/workers/clear_shared_runners_minutes_worker_spec.rb
View file @
65cd7ad5
...
@@ -147,11 +147,12 @@ RSpec.describe ClearSharedRunnersMinutesWorker do
...
@@ -147,11 +147,12 @@ RSpec.describe ClearSharedRunnersMinutesWorker do
end
end
it
'runs a worker per batch'
do
it
'runs a worker per batch'
do
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_async
).
with
(
2
,
4
)
# Spread evenly accross 3 hours (10800 seconds)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_async
).
with
(
5
,
7
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_in
).
with
(
0
.
seconds
,
2
,
4
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_async
).
with
(
8
,
10
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_in
).
with
(
2700
.
seconds
,
5
,
7
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_async
).
with
(
11
,
13
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_in
).
with
(
5400
.
seconds
,
8
,
10
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_async
).
with
(
14
,
16
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_in
).
with
(
8100
.
seconds
,
11
,
13
)
expect
(
Ci
::
BatchResetMinutesWorker
).
to
receive
(
:perform_in
).
with
(
10800
.
seconds
,
14
,
16
)
subject
subject
end
end
...
...
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