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
7bba90cd
Commit
7bba90cd
authored
Jun 26, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract EachShardWorker into a concern
parent
648056b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
34 deletions
+39
-34
app/workers/concerns/each_shard_worker.rb
app/workers/concerns/each_shard_worker.rb
+36
-0
ee/app/workers/geo/scheduler/per_shard_scheduler_worker.rb
ee/app/workers/geo/scheduler/per_shard_scheduler_worker.rb
+2
-27
ee/spec/workers/geo/scheduler/per_shard_scheduler_worker_spec.rb
.../workers/geo/scheduler/per_shard_scheduler_worker_spec.rb
+1
-7
No files found.
app/workers/concerns/each_shard_worker.rb
0 → 100644
View file @
7bba90cd
module
EachShardWorker
extend
ActiveSupport
::
Concern
include
::
Gitlab
::
Utils
::
StrongMemoize
HEALTHY_SHARD_CHECKS
=
[
Gitlab
::
HealthChecks
::
GitalyCheck
].
freeze
def
each_shard
eligible_shard_names
.
each
do
|
shard_name
|
yield
shard_name
end
end
# override when you want to filter out some shards
def
eligible_shard_names
healthy_shard_names
end
def
healthy_shard_names
strong_memoize
(
:healthy_shard_names
)
do
# For now, we need to perform both Gitaly and direct filesystem checks to ensure
# the shard is healthy. We take the intersection of the successful checks
# as the healthy shards.
healthy_ready_shards
.
map
{
|
result
|
result
.
labels
[
:shard
]
}.
compact
.
uniq
end
end
def
healthy_ready_shards
ready_shards
.
map
{
|
result
|
result
.
select
(
&
:success
)
}.
inject
(
:&
)
end
def
ready_shards
HEALTHY_SHARD_CHECKS
.
map
(
&
:readiness
)
end
end
ee/app/workers/geo/scheduler/per_shard_scheduler_worker.rb
View file @
7bba90cd
...
@@ -3,43 +3,18 @@ module Geo
...
@@ -3,43 +3,18 @@ module Geo
class
PerShardSchedulerWorker
class
PerShardSchedulerWorker
include
ApplicationWorker
include
ApplicationWorker
include
CronjobQueue
include
CronjobQueue
include
::
Gitlab
::
Utils
::
StrongMemoize
include
::
Gitlab
::
Geo
::
LogHelpers
include
::
Gitlab
::
Geo
::
LogHelpers
include
::
EachShardWorker
HEALTHY_SHARD_CHECKS
=
[
Gitlab
::
HealthChecks
::
GitalyCheck
].
freeze
def
perform
def
perform
Gitlab
::
Geo
::
ShardHealthCache
.
update
(
eligible_shard_names
)
Gitlab
::
Geo
::
ShardHealthCache
.
update
(
eligible_shard_names
)
eligible_shard_names
.
each
{
|
shard_name
|
schedule_job
(
shard_name
)
}
each_shard
{
|
shard_name
|
schedule_job
(
shard_name
)
}
end
def
eligible_shard_names
healthy_shard_names
end
end
def
schedule_job
(
shard_name
)
def
schedule_job
(
shard_name
)
raise
NotImplementedError
raise
NotImplementedError
end
end
def
healthy_shard_names
strong_memoize
(
:healthy_shard_names
)
do
# For now, we need to perform both Gitaly and direct filesystem checks to ensure
# the shard is healthy. We take the intersection of the successful checks
# as the healthy shards.
healthy_ready_shards
.
map
{
|
result
|
result
.
labels
[
:shard
]
}.
compact
.
uniq
end
end
def
ready_shards
HEALTHY_SHARD_CHECKS
.
map
(
&
:readiness
)
end
def
healthy_ready_shards
ready_shards
.
map
{
|
result
|
result
.
select
(
&
:success
)
}.
inject
(
:&
)
end
end
end
end
end
end
end
ee/spec/workers/geo/scheduler/per_shard_scheduler_worker_spec.rb
View file @
7bba90cd
...
@@ -17,12 +17,6 @@ describe Geo::Scheduler::PerShardSchedulerWorker do
...
@@ -17,12 +17,6 @@ describe Geo::Scheduler::PerShardSchedulerWorker do
expect
(
described_class
).
to
include_module
(
::
Gitlab
::
Geo
::
LogHelpers
)
expect
(
described_class
).
to
include_module
(
::
Gitlab
::
Geo
::
LogHelpers
)
end
end
it
'includes Gitaly health checks'
do
expect
(
described_class
::
HEALTHY_SHARD_CHECKS
).
to
include
(
Gitlab
::
HealthChecks
::
GitalyCheck
)
end
describe
'instance methods'
do
describe
'instance methods'
do
subject
(
:per_shard_scheduler_worker
)
{
described_class
.
new
}
subject
(
:per_shard_scheduler_worker
)
{
described_class
.
new
}
...
@@ -47,7 +41,7 @@ describe Geo::Scheduler::PerShardSchedulerWorker do
...
@@ -47,7 +41,7 @@ describe Geo::Scheduler::PerShardSchedulerWorker do
end
end
describe
'#ready_shards'
do
describe
'#ready_shards'
do
let
(
:ready_shards
)
{
[
[
default_shard
,
other_shard
,
unhealthy_shard
]
]
}
let
(
:ready_shards
)
{
[
default_shard
,
other_shard
,
unhealthy_shard
]
}
it
"returns an array of ready shards"
do
it
"returns an array of ready shards"
do
expect
(
per_shard_scheduler_worker
.
ready_shards
).
to
eq
(
ready_shards
)
expect
(
per_shard_scheduler_worker
.
ready_shards
).
to
eq
(
ready_shards
)
...
...
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