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
7a4c3dd0
Commit
7a4c3dd0
authored
Apr 01, 2022
by
George Koltsov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not throttle enqueueing of BulkImports::EntityWorker
parent
c88f43cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
38 deletions
+7
-38
app/workers/bulk_import_worker.rb
app/workers/bulk_import_worker.rb
+3
-19
spec/workers/bulk_import_worker_spec.rb
spec/workers/bulk_import_worker_spec.rb
+4
-19
No files found.
app/workers/bulk_import_worker.rb
View file @
7a4c3dd0
...
...
@@ -3,15 +3,12 @@
class
BulkImportWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
data_consistency
:alway
s
PERFORM_DELAY
=
5
.
second
s
data_consistency
:always
feature_category
:importers
sidekiq_options
retry:
false
,
dead:
false
PERFORM_DELAY
=
5
.
seconds
DEFAULT_BATCH_SIZE
=
5
def
perform
(
bulk_import_id
)
@bulk_import
=
BulkImport
.
find_by_id
(
bulk_import_id
)
...
...
@@ -19,11 +16,10 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
return
if
@bulk_import
.
finished?
||
@bulk_import
.
failed?
return
@bulk_import
.
fail_op!
if
all_entities_failed?
return
@bulk_import
.
finish!
if
all_entities_processed?
&&
@bulk_import
.
started?
return
re_enqueue
if
max_batch_size_exceeded?
# Do not start more jobs if max allowed are already running
@bulk_import
.
start!
if
@bulk_import
.
created?
created_entities
.
fi
rst
(
next_batch_size
).
each
do
|
entity
|
created_entities
.
fi
nd_
each
do
|
entity
|
entity
.
create_pipeline_trackers!
BulkImports
::
ExportRequestWorker
.
perform_async
(
entity
.
id
)
...
...
@@ -45,10 +41,6 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
@entities
||=
@bulk_import
.
entities
end
def
started_entities
entities
.
with_status
(
:started
)
end
def
created_entities
entities
.
with_status
(
:created
)
end
...
...
@@ -61,14 +53,6 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
entities
.
all?
{
|
entity
|
entity
.
failed?
}
end
def
max_batch_size_exceeded?
started_entities
.
count
>=
DEFAULT_BATCH_SIZE
end
def
next_batch_size
[
DEFAULT_BATCH_SIZE
-
started_entities
.
count
,
0
].
max
end
# A new BulkImportWorker job is enqueued to either
# - Process the new BulkImports::Entity created during import (e.g. for the subgroups)
# - Or to mark the `bulk_import` as finished
...
...
spec/workers/bulk_import_worker_spec.rb
View file @
7a4c3dd0
...
...
@@ -56,17 +56,6 @@ RSpec.describe BulkImportWorker do
end
end
context
'when maximum allowed number of import entities in progress'
do
it
'reenqueues itself'
do
bulk_import
=
create
(
:bulk_import
,
:started
)
(
described_class
::
DEFAULT_BATCH_SIZE
+
1
).
times
{
|
_
|
create
(
:bulk_import_entity
,
:started
,
bulk_import:
bulk_import
)
}
expect
(
described_class
).
to
receive
(
:perform_in
).
with
(
described_class
::
PERFORM_DELAY
,
bulk_import
.
id
)
subject
.
perform
(
bulk_import
.
id
)
end
end
context
'when bulk import is created'
do
it
'marks bulk import as started'
do
bulk_import
=
create
(
:bulk_import
,
:created
)
...
...
@@ -93,21 +82,17 @@ RSpec.describe BulkImportWorker do
context
'when there are created entities to process'
do
let_it_be
(
:bulk_import
)
{
create
(
:bulk_import
,
:created
)
}
before
do
stub_const
(
"
#{
described_class
}
::DEFAULT_BATCH_SIZE"
,
1
)
end
it
'marks a batch of entities as started, enqueues EntityWorker, ExportRequestWorker and reenqueues'
do
it
'marks all entities as started, enqueues EntityWorker, ExportRequestWorker and reenqueues'
do
create
(
:bulk_import_entity
,
:created
,
bulk_import:
bulk_import
)
create
(
:bulk_import_entity
,
:created
,
bulk_import:
bulk_import
)
expect
(
described_class
).
to
receive
(
:perform_in
).
with
(
described_class
::
PERFORM_DELAY
,
bulk_import
.
id
)
expect
(
BulkImports
::
EntityWorker
).
to
receive
(
:perform_async
)
expect
(
BulkImports
::
ExportRequestWorker
).
to
receive
(
:perform_async
)
expect
(
BulkImports
::
EntityWorker
).
to
receive
(
:perform_async
)
.
twice
expect
(
BulkImports
::
ExportRequestWorker
).
to
receive
(
:perform_async
)
.
twice
subject
.
perform
(
bulk_import
.
id
)
expect
(
bulk_import
.
entities
.
map
(
&
:status_name
)).
to
contain_exactly
(
:
crea
ted
,
:started
)
expect
(
bulk_import
.
entities
.
map
(
&
:status_name
)).
to
contain_exactly
(
:
star
ted
,
:started
)
end
context
'when there are project entities to process'
do
...
...
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