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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
c33cedd0
Commit
c33cedd0
authored
May 22, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use each_batch to find rows efficiently with group_by
parent
d10fbde4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
app/workers/rescue_stale_live_trace_worker.rb
app/workers/rescue_stale_live_trace_worker.rb
+5
-4
No files found.
app/workers/rescue_stale_live_trace_worker.rb
View file @
c33cedd0
...
@@ -6,20 +6,21 @@ class RescueStaleLiveTraceWorker
...
@@ -6,20 +6,21 @@ class RescueStaleLiveTraceWorker
# Reschedule to archive live traces
# Reschedule to archive live traces
#
#
# The target jobs are with the following conditions
# The target jobs are with the following conditions
# - Finished 1
day
ago, but it has not had an acthived trace yet
# - Finished 1
hour
ago, but it has not had an acthived trace yet
# Jobs finished 1
day
ago should have an archived trace. Probably ArchiveTraceWorker failed by Sidekiq's inconsistancy
# Jobs finished 1
hour
ago should have an archived trace. Probably ArchiveTraceWorker failed by Sidekiq's inconsistancy
Ci
::
BuildTraceChunk
Ci
::
BuildTraceChunk
.
include
(
EachBatch
)
.
select
(
:build_id
)
.
select
(
:build_id
)
.
group
(
:build_id
)
.
group
(
:build_id
)
.
joins
(
:build
)
.
joins
(
:build
)
.
merge
(
Ci
::
Build
.
finished
)
.
merge
(
Ci
::
Build
.
finished
)
.
where
(
'ci_builds.finished_at < ?'
,
1
.
hour
.
ago
)
.
where
(
'ci_builds.finished_at < ?'
,
1
.
hour
.
ago
)
.
each
do
|
chunks
|
# TODO: find_each gives an error because of group_by
.
each
_batch
(
column: :build_id
)
do
|
chunks
|
build_ids
=
chunks
.
map
{
|
chunk
|
[
chunk
.
build_id
]
}
build_ids
=
chunks
.
map
{
|
chunk
|
[
chunk
.
build_id
]
}
ArchiveTraceWorker
.
bulk_perform_async
(
build_ids
)
ArchiveTraceWorker
.
bulk_perform_async
(
build_ids
)
Rails
.
logger
.
warning
"Scheduled to archive stale live traces from
#{
build_ids
.
min
}
to
#{
build_ids
.
max
}
"
Rails
.
logger
.
info
"Scheduled to archive stale live traces from
#{
build_ids
.
min
}
to
#{
build_ids
.
max
}
"
end
end
end
end
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