Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FS-SC
AsapoWorker
Commits
0ebfec4e
Commit
0ebfec4e
authored
Jul 08, 2021
by
Mikhail Karnevskiy
Browse files
Move check if it make sense to set start position to dedicated function.
parent
110a35e5
Pipeline
#8013
passed with stage
in 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/AsapoWorker/application.py
View file @
0ebfec4e
...
...
@@ -163,8 +163,7 @@ class Application:
consumer
.
stream
=
stream
if
sender
:
sender
.
stream
=
stream
if
hasattr
(
self
.
worker_class
,
'calculate_start_ids'
):
_set_start_position
(
self
.
options
,
consumer
,
sender
,
self
.
worker_class
)
_set_start_position
(
self
.
options
,
consumer
,
sender
,
self
.
worker_class
)
worker
=
create_instance_from_configurable
(
self
.
worker_class
,
self
.
options
[
"worker"
])
...
...
@@ -221,6 +220,12 @@ class Application:
def
_set_start_position
(
options
,
consumer
,
sender
,
worker_class
):
if
(
not
hasattr
(
worker_class
,
'calculate_start_ids'
)
or
not
hasattr
(
worker_class
,
'calculate_start_index'
)):
log
.
info
(
"Worker does not support starting from the last processed "
"record. Starting from the beginning instead"
)
return
if
(
"start_id"
not
in
options
[
"worker"
]
or
"start_id"
not
in
options
[
"receiver"
]
or
"start_index"
not
in
options
[
"worker"
]):
...
...
@@ -246,26 +251,21 @@ def _set_start_position(options, consumer, sender, worker_class):
last_output_metadata
=
None
if
last_output_metadata
:
try
:
input_start_id
,
output_start_id
=
(
worker_class
.
calculate_start_ids
(
last_output_metadata
))
input_start_id
,
output_start_id
=
(
worker_class
.
calculate_start_ids
(
last_output_metadata
))
output_start_index
=
worker_class
.
calculate_start_index
(
last_output_metadata
)
except
AttributeError
:
log
.
warning
(
"Worker does not support starting from the last processed "
"record. Starting from the beginning instead"
)
else
:
consumer
.
set_start_id
(
input_start_id
)
output_start_index
=
worker_class
.
calculate_start_index
(
last_output_metadata
)
consumer
.
set_start_id
(
input_start_id
)
log
.
info
(
"Setting worker option start_id=%s"
,
output_start_id
)
options
[
"worker"
][
"start_id"
]
=
output_start_id
log
.
info
(
"Setting worker option start_id=%s"
,
output_start_id
)
options
[
"worker"
][
"start_id"
]
=
output_start_id
log
.
info
(
"Setting worker option start_index=%s"
,
output_start_index
)
options
[
"worker"
][
"start_index"
]
=
output_start_index
log
.
info
(
"Setting worker option start_index=%s"
,
output_start_index
)
options
[
"worker"
][
"start_index"
]
=
output_start_index
def
_unset_start_position
(
options
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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