Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
3ab410b6
Commit
3ab410b6
authored
3 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Use element_id instead of element in update_activity
parent
8f5cf687
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!85
Use element_id instead of element in update_activity
Pipeline
#78407
passed
3 years ago
Stage: release
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/__init__.py
+12
-12
12 additions, 12 deletions
arkindex_worker/worker/__init__.py
tests/test_elements_worker/test_worker.py
+3
-10
3 additions, 10 deletions
tests/test_elements_worker/test_worker.py
with
15 additions
and
22 deletions
arkindex_worker/worker/__init__.py
+
12
−
12
View file @
3ab410b6
...
@@ -99,16 +99,16 @@ class ElementsWorker(
...
@@ -99,16 +99,16 @@ class ElementsWorker(
logger
.
info
(
f
"
Processing
{
element
}
(
{
i
}
/
{
count
}
)
"
)
logger
.
info
(
f
"
Processing
{
element
}
(
{
i
}
/
{
count
}
)
"
)
# Report start of process, run process, then report end of process
# Report start of process, run process, then report end of process
self
.
update_activity
(
element
,
ActivityState
.
Started
)
self
.
update_activity
(
element
.
id
,
ActivityState
.
Started
)
self
.
process_element
(
element
)
self
.
process_element
(
element
)
self
.
update_activity
(
element
,
ActivityState
.
Processed
)
self
.
update_activity
(
element
.
id
,
ActivityState
.
Processed
)
except
ErrorResponse
as
e
:
except
ErrorResponse
as
e
:
failed
+=
1
failed
+=
1
logger
.
warning
(
logger
.
warning
(
f
"
An API error occurred while processing element
{
element_id
}
:
{
e
.
title
}
-
{
e
.
content
}
"
,
f
"
An API error occurred while processing element
{
element_id
}
:
{
e
.
title
}
-
{
e
.
content
}
"
,
exc_info
=
e
if
self
.
args
.
verbose
else
None
,
exc_info
=
e
if
self
.
args
.
verbose
else
None
,
)
)
self
.
update_activity
(
element
,
ActivityState
.
Error
)
self
.
update_activity
(
element
_id
,
ActivityState
.
Error
)
self
.
report
.
error
(
element_id
,
e
)
self
.
report
.
error
(
element_id
,
e
)
except
Exception
as
e
:
except
Exception
as
e
:
failed
+=
1
failed
+=
1
...
@@ -116,7 +116,7 @@ class ElementsWorker(
...
@@ -116,7 +116,7 @@ class ElementsWorker(
f
"
Failed running worker on element
{
element_id
}
:
{
e
}
"
,
f
"
Failed running worker on element
{
element_id
}
:
{
e
}
"
,
exc_info
=
e
if
self
.
args
.
verbose
else
None
,
exc_info
=
e
if
self
.
args
.
verbose
else
None
,
)
)
self
.
update_activity
(
element
,
ActivityState
.
Error
)
self
.
update_activity
(
element
_id
,
ActivityState
.
Error
)
self
.
report
.
error
(
element_id
,
e
)
self
.
report
.
error
(
element_id
,
e
)
# Save report as local artifact
# Save report as local artifact
...
@@ -134,14 +134,14 @@ class ElementsWorker(
...
@@ -134,14 +134,14 @@ class ElementsWorker(
def
process_element
(
self
,
element
):
def
process_element
(
self
,
element
):
"""
Override this method to analyze an Arkindex element from the provided list
"""
"""
Override this method to analyze an Arkindex element from the provided list
"""
def
update_activity
(
self
,
element
,
state
):
def
update_activity
(
self
,
element
_id
,
state
):
"""
"""
Update worker activity for this element
Update worker activity for this element
This method should not raise a runtime exception, but simply warn users
This method should not raise a runtime exception, but simply warn users
"""
"""
assert
element
and
isinstance
(
assert
element
_id
and
isinstance
(
element
,
Element
element
_id
,
str
),
"
element shouldn
'
t be null and should be of type
Element
"
),
"
element
_id
shouldn
'
t be null and should be of type
str
"
assert
isinstance
(
state
,
ActivityState
),
"
state should be an ActivityState
"
assert
isinstance
(
state
,
ActivityState
),
"
state should be an ActivityState
"
if
not
self
.
features
.
get
(
"
workers_activity
"
):
if
not
self
.
features
.
get
(
"
workers_activity
"
):
...
@@ -157,17 +157,17 @@ class ElementsWorker(
...
@@ -157,17 +157,17 @@ class ElementsWorker(
"
UpdateWorkerActivity
"
,
"
UpdateWorkerActivity
"
,
id
=
self
.
worker_version_id
,
id
=
self
.
worker_version_id
,
body
=
{
body
=
{
"
element_id
"
:
element
.
id
,
"
element_id
"
:
element
_
id
,
"
state
"
:
state
.
value
,
"
state
"
:
state
.
value
,
},
},
)
)
logger
.
debug
(
f
"
Updated activity of element
{
element
.
id
}
to
{
state
}
"
)
logger
.
debug
(
f
"
Updated activity of element
{
element
_
id
}
to
{
state
}
"
)
return
out
return
out
except
ErrorResponse
as
e
:
except
ErrorResponse
as
e
:
logger
.
warning
(
logger
.
warning
(
f
"
Failed to update activity of element
{
element
.
id
}
to
{
state
.
value
}
due to an API error:
{
e
.
content
}
"
f
"
Failed to update activity of element
{
element
_
id
}
to
{
state
.
value
}
due to an API error:
{
e
.
content
}
"
)
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
logger
.
warning
(
f
"
Failed to update activity of element
{
element
.
id
}
to
{
state
.
value
}
:
{
e
}
"
f
"
Failed to update activity of element
{
element
_
id
}
to
{
state
.
value
}
:
{
e
}
"
)
)
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_worker.py
+
3
−
10
View file @
3ab410b6
...
@@ -4,7 +4,6 @@ import json
...
@@ -4,7 +4,6 @@ import json
import
pytest
import
pytest
from
apistar.exceptions
import
ErrorResponse
from
apistar.exceptions
import
ErrorResponse
from
arkindex_worker.models
import
Element
from
arkindex_worker.worker
import
ActivityState
from
arkindex_worker.worker
import
ActivityState
# Common API calls for all workers
# Common API calls for all workers
...
@@ -81,9 +80,7 @@ def test_feature_disabled(responses, mock_elements_worker):
...
@@ -81,9 +80,7 @@ def test_feature_disabled(responses, mock_elements_worker):
"""
Test disabled calls do not trigger any API calls
"""
"""
Test disabled calls do not trigger any API calls
"""
assert
not
mock_elements_worker
.
is_read_only
assert
not
mock_elements_worker
.
is_read_only
out
=
mock_elements_worker
.
update_activity
(
out
=
mock_elements_worker
.
update_activity
(
"
1234-deadbeef
"
,
ActivityState
.
Processed
)
Element
({
"
id
"
:
"
1234-deadbeef
"
}),
ActivityState
.
Processed
)
assert
out
is
None
assert
out
is
None
assert
len
(
responses
.
calls
)
==
2
assert
len
(
responses
.
calls
)
==
2
...
@@ -98,9 +95,7 @@ def test_readonly(responses, mock_elements_worker):
...
@@ -98,9 +95,7 @@ def test_readonly(responses, mock_elements_worker):
assert
mock_elements_worker
.
is_read_only
is
True
assert
mock_elements_worker
.
is_read_only
is
True
mock_elements_worker
.
features
[
"
workers_activity
"
]
=
True
mock_elements_worker
.
features
[
"
workers_activity
"
]
=
True
out
=
mock_elements_worker
.
update_activity
(
out
=
mock_elements_worker
.
update_activity
(
"
1234-deadbeef
"
,
ActivityState
.
Processed
)
Element
({
"
id
"
:
"
1234-deadbeef
"
}),
ActivityState
.
Processed
)
assert
out
is
None
assert
out
is
None
assert
len
(
responses
.
calls
)
==
2
assert
len
(
responses
.
calls
)
==
2
...
@@ -122,9 +117,7 @@ def test_update_call(responses, mock_elements_worker):
...
@@ -122,9 +117,7 @@ def test_update_call(responses, mock_elements_worker):
# Enable worker activity
# Enable worker activity
mock_elements_worker
.
features
[
"
workers_activity
"
]
=
True
mock_elements_worker
.
features
[
"
workers_activity
"
]
=
True
out
=
mock_elements_worker
.
update_activity
(
out
=
mock_elements_worker
.
update_activity
(
"
1234-deadbeef
"
,
ActivityState
.
Processed
)
Element
({
"
id
"
:
"
1234-deadbeef
"
}),
ActivityState
.
Processed
)
# Check the response received by worker
# Check the response received by worker
assert
out
==
{
assert
out
==
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment