Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
djangoldp-packages
djangoldp
Commits
deb35d4e
Commit
deb35d4e
authored
4 years ago
by
Calum Mackervoy
Committed by
Jean-Baptiste Pasquier
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feature: configurable activity delay per-request
parent
a56031fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/activities/services.py
+8
-11
8 additions, 11 deletions
djangoldp/activities/services.py
with
8 additions
and
11 deletions
djangoldp/activities/services.py
+
8
−
11
View file @
deb35d4e
...
...
@@ -66,7 +66,7 @@ class ActivityQueueService:
while
True
:
# wait for queue item to manifest
item
=
queue
.
get
()
time
.
sleep
(
DEFAULT_ACTIVITY_DELAY
)
time
.
sleep
(
item
[
2
]
)
cls
.
_activity_queue_worker
(
item
[
0
],
item
[
1
])
cls
.
queue
.
task_done
()
...
...
@@ -187,9 +187,6 @@ class ActivityQueueService:
return
groub_b
return
[]
def
get_fail_response
():
return
{
'
response
'
:
None
,
'
activity
'
:
None
}
types
=
get_related_activities
(
scheduled_activity
.
type
)
if
len
(
types
)
>
0
:
scheduled
=
ScheduledActivity
.
objects
.
filter
(
external_id
=
scheduled_activity
.
external_id
,
...
...
@@ -201,15 +198,15 @@ class ActivityQueueService:
if
len
(
scheduled
)
>
0
:
scheduled_activity
.
delete
()
return
get_fail_response
()
return
if
scheduled_activity
.
type
==
'
update
'
and
not
cls
.
_update_is_new
(
url
,
scheduled_activity
):
scheduled_activity
.
delete
()
return
get_fail_response
()
return
if
scheduled_activity
.
type
in
[
'
add
'
,
'
remove
'
]
and
not
cls
.
_add_remove_is_new
(
url
,
scheduled_activity
):
scheduled_activity
.
delete
()
return
get_fail_response
()
return
cls
.
_send_activity
(
url
,
scheduled_activity
)
...
...
@@ -302,11 +299,11 @@ class ActivityQueueService:
return
True
@classmethod
def
_push_to_queue
(
cls
,
url
,
scheduled_activity
):
def
_push_to_queue
(
cls
,
url
,
scheduled_activity
,
delay
=
DEFAULT_ACTIVITY_DELAY
):
'''
wrapper to check for singleton initialization before pushing
'''
if
not
cls
.
initialized
:
cls
.
start
()
cls
.
queue
.
put
([
url
,
scheduled_activity
])
cls
.
queue
.
put
([
url
,
scheduled_activity
,
delay
])
@classmethod
def
resend_activity
(
cls
,
url
,
scheduled_activity
,
failed
=
True
):
...
...
@@ -323,7 +320,7 @@ class ActivityQueueService:
cls
.
_push_to_queue
(
url
,
scheduled_activity
)
@classmethod
def
send_activity
(
cls
,
url
,
activity
,
auth
=
None
):
def
send_activity
(
cls
,
url
,
activity
,
auth
=
None
,
delay
=
DEFAULT_ACTIVITY_DELAY
):
'''
saves a ScheduledActivity for the parameterised activity and passes it to the queue
:param url: the recipient url inbox
...
...
@@ -337,7 +334,7 @@ class ActivityQueueService:
# schedule the activity
scheduled
=
cls
.
_save_sent_activity
(
activity
,
ScheduledActivity
,
external_id
=
url
,
type
=
activity
.
get
(
'
type
'
,
None
))
cls
.
_push_to_queue
(
url
,
scheduled
)
cls
.
_push_to_queue
(
url
,
scheduled
,
delay
)
@classmethod
def
_save_sent_activity
(
cls
,
activity
,
model_represenation
=
ActivityModel
,
success
=
False
,
external_id
=
None
,
type
=
None
,
...
...
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