Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
ab45bded
Commit
ab45bded
authored
Feb 06, 2017
by
Robert Raposa
Committed by
GitHub
Feb 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #230 from edx/robrap/improve-rebuild-index
TNL-6464: Minor changes to rebuild_index.
parents
5d43d81f
13f5ffac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
+22
-12
lib/task_helpers.rb
+6
-3
lib/tasks/search.rake
+11
-5
spec/lib/tasks/search_rake_spec.rb
+5
-4
No files found.
lib/task_helpers.rb
View file @
ab45bded
...
@@ -14,7 +14,8 @@ module TaskHelpers
...
@@ -14,7 +14,8 @@ module TaskHelpers
# +alias_name+:: (optional) The alias to point to the new index.
# +alias_name+:: (optional) The alias to point to the new index.
# +batch_size+:: (optional) The number of elements to index at a time. Defaults to 500.
# +batch_size+:: (optional) The number of elements to index at a time. Defaults to 500.
# +sleep_time+:: (optional) The number of seconds to sleep between batches. Defaults to 0.
# +sleep_time+:: (optional) The number of seconds to sleep between batches. Defaults to 0.
def
self
.
rebuild_index
(
alias_name
=
nil
,
batch_size
=
500
,
sleep_time
=
0
)
# +extra_catchup_minutes+:: (optional) The number of extra minutes to catchup. Defaults to 5.
def
self
.
rebuild_index
(
alias_name
=
nil
,
batch_size
=
500
,
sleep_time
=
0
,
extra_catchup_minutes
=
5
)
initial_start_time
=
Time
.
now
initial_start_time
=
Time
.
now
index_name
=
create_index
()
index_name
=
create_index
()
...
@@ -30,10 +31,12 @@ module TaskHelpers
...
@@ -30,10 +31,12 @@ module TaskHelpers
# Just in case initial rebuild took days and first catch up takes hours,
# Just in case initial rebuild took days and first catch up takes hours,
# we catch up once before the alias move and once afterwards.
# we catch up once before the alias move and once afterwards.
first_catchup_start_time
=
Time
.
now
first_catchup_start_time
=
Time
.
now
catchup_index
(
initial_start_time
,
index_name
,
batch_size
,
sleep_time
)
adjusted_start_time
=
initial_start_time
-
(
extra_catchup_minutes
*
60
)
catchup_index
(
adjusted_start_time
,
index_name
,
batch_size
,
sleep_time
)
move_alias
(
alias_name
,
index_name
,
force_delete:
true
)
move_alias
(
alias_name
,
index_name
,
force_delete:
true
)
catchup_index
(
first_catchup_start_time
,
alias_name
,
batch_size
,
sleep_time
)
adjusted_start_time
=
first_catchup_start_time
-
(
extra_catchup_minutes
*
60
)
catchup_index
(
adjusted_start_time
,
alias_name
,
batch_size
,
sleep_time
)
end
end
LOG
.
info
"Rebuild index complete."
LOG
.
info
"Rebuild index complete."
...
...
lib/tasks/search.rake
View file @
ab45bded
...
@@ -11,12 +11,18 @@ namespace :search do
...
@@ -11,12 +11,18 @@ namespace :search do
end
end
desc
'Rebuilds a new index of all data from the database and then updates alias.'
desc
'Rebuilds a new index of all data from the database and then updates alias.'
task
:rebuild_index
,
[
:call_move_alias
,
:batch_size
,
:sleep_time
]
=>
:environment
do
|
t
,
args
|
task
:rebuild_index
,
[
:call_move_alias
,
:batch_size
,
:sleep_time
,
:extra_catchup_minutes
]
=>
:environment
do
|
t
,
args
|
args
.
with_defaults
(
:call_move_alias
=>
fals
e
)
args
.
with_defaults
(
:call_move_alias
=>
tru
e
)
args
.
with_defaults
(
:batch_size
=>
500
)
args
.
with_defaults
(
:batch_size
=>
500
)
args
.
with_defaults
(
:sleep_time
=>
0
)
args
.
with_defaults
(
:sleep_time
=>
0
)
# sleep time between batches in seconds
alias_name
=
args
[
:call_move_alias
]
?
Content
::
ES_INDEX_NAME
:
nil
args
.
with_defaults
(
:extra_catchup_minutes
=>
5
)
# additional catchup time in minutes
TaskHelpers
::
ElasticsearchHelper
.
rebuild_index
(
alias_name
,
args
[
:batch_size
].
to_i
,
args
[
:sleep_time
].
to_i
)
alias_name
=
args
[
:call_move_alias
]
===
true
?
Content
::
ES_INDEX_NAME
:
nil
TaskHelpers
::
ElasticsearchHelper
.
rebuild_index
(
alias_name
,
args
[
:batch_size
].
to_i
,
args
[
:sleep_time
].
to_i
,
args
[
:extra_catchup_minutes
].
to_i
)
end
end
desc
'Generate a new, empty physical index, without bringing it online.'
desc
'Generate a new, empty physical index, without bringing it online.'
...
...
spec/lib/tasks/search_rake_spec.rb
View file @
ab45bded
...
@@ -11,21 +11,22 @@ describe "search:rebuild_index" do
...
@@ -11,21 +11,22 @@ describe "search:rebuild_index" do
its
(
:prerequisites
)
{
should
include
(
"environment"
)
}
its
(
:prerequisites
)
{
should
include
(
"environment"
)
}
it
"calls rebuild_index with defaults"
do
it
"calls rebuild_index with defaults"
do
TaskHelpers
::
ElasticsearchHelper
.
should_receive
(
:rebuild_index
).
with
(
nil
,
500
,
0
)
TaskHelpers
::
ElasticsearchHelper
.
should_receive
(
:rebuild_index
).
with
(
Content
::
ES_INDEX_NAME
,
500
,
0
,
5
)
subject
.
invoke
subject
.
invoke
end
end
it
"calls rebuild_index with arguments"
do
it
"calls rebuild_index with arguments"
do
# Rake calls receive arguments as strings.
# Rake calls receive arguments as strings.
call_move_alias
=
'
tru
e'
call_move_alias
=
'
fals
e'
batch_size
=
'100'
batch_size
=
'100'
sleep_time
=
'2'
sleep_time
=
'2'
extra_catchup_minutes
=
'10'
TaskHelpers
::
ElasticsearchHelper
.
should_receive
(
:rebuild_index
).
with
(
TaskHelpers
::
ElasticsearchHelper
.
should_receive
(
:rebuild_index
).
with
(
Content
::
ES_INDEX_NAME
,
batch_size
.
to_i
,
sleep_time
.
to_i
nil
,
batch_size
.
to_i
,
sleep_time
.
to_i
,
extra_catchup_minutes
.
to_i
)
)
subject
.
invoke
(
call_move_alias
,
batch_size
,
sleep_time
)
subject
.
invoke
(
call_move_alias
,
batch_size
,
sleep_time
,
extra_catchup_minutes
)
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