Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
celery-haystack-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
celery-haystack-ng
Commits
4ac097e9
Verified
Commit
4ac097e9
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Ensure task is enqueued on commit
parent
d994a221
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
celery_haystack/conf.py
+1
-8
1 addition, 8 deletions
celery_haystack/conf.py
celery_haystack/signals.py
+20
-13
20 additions, 13 deletions
celery_haystack/signals.py
celery_haystack/utils.py
+0
-29
0 additions, 29 deletions
celery_haystack/utils.py
with
21 additions
and
50 deletions
celery_haystack/conf.py
+
1
−
8
View file @
4ac097e9
...
@@ -55,11 +55,4 @@ class CeleryHaystack(AppConf):
...
@@ -55,11 +55,4 @@ class CeleryHaystack(AppConf):
return
data
return
data
signal_processor
=
getattr
(
settings
,
'
HAYSTACK_SIGNAL_PROCESSOR
'
,
None
)
signal_processor
=
getattr
(
settings
,
'
HAYSTACK_SIGNAL_PROCESSOR
'
,
"
celery_haystack.signals.CelerySignalProcessor
"
)
if
signal_processor
is
None
:
raise
ImproperlyConfigured
(
"
When using celery-haystack with Haystack 2.X
"
"
the HAYSTACK_SIGNAL_PROCESSOR setting must be
"
"
set. Use
'
celery_haystack.signals.
"
"
CelerySignalProcessor
'
as default.
"
)
This diff is collapsed.
Click to expand it.
celery_haystack/signals.py
+
20
−
13
View file @
4ac097e9
from
django.db
import
transaction
from
django.db.models
import
signals
from
django.db.models
import
signals
from
haystack.signals
import
Bas
eSignalProcessor
from
haystack.signals
import
Realtim
eSignalProcessor
from
haystack.exceptions
import
NotHandled
from
haystack.exceptions
import
NotHandled
from
haystack.utils
import
get_identifier
from
haystack.utils
import
get_identifier
from
.utils
import
enqueue_task
from
.conf
import
settings
from
.utils
import
get_update_task
from
.indexes
import
CelerySearchIndex
from
.indexes
import
CelerySearchIndex
class
CelerySignalProcessor
(
Bas
eSignalProcessor
):
class
CelerySignalProcessor
(
Realtim
eSignalProcessor
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_queue
=
[]
self
.
_queue
=
[]
def
setup
(
self
):
def
setup
(
self
):
signals
.
post_save
.
connect
(
self
.
enqueue_save
)
transaction
.
on_commit
(
self
.
run_task
)
s
ignals
.
post_delete
.
connect
(
self
.
enqueue_delete
)
s
uper
().
setup
(
)
def
teardown
(
self
):
def
handle_save
(
self
,
sender
,
instance
,
**
kwargs
):
signals
.
post_save
.
disconnect
(
self
.
enqueue_save
)
signals
.
post_delete
.
disconnect
(
self
.
enqueue_delete
)
enqueue_task
(
self
.
_queue
)
def
enqueue_save
(
self
,
sender
,
instance
,
**
kwargs
):
return
self
.
enqueue
(
'
update
'
,
instance
,
sender
,
**
kwargs
)
return
self
.
enqueue
(
'
update
'
,
instance
,
sender
,
**
kwargs
)
def
enqueu
e_delete
(
self
,
sender
,
instance
,
**
kwargs
):
def
handl
e_delete
(
self
,
sender
,
instance
,
**
kwargs
):
return
self
.
enqueue
(
'
delete
'
,
instance
,
sender
,
**
kwargs
)
return
self
.
enqueue
(
'
delete
'
,
instance
,
sender
,
**
kwargs
)
def
run_task
(
self
):
options
=
{}
if
settings
.
CELERY_HAYSTACK_QUEUE
:
options
[
'
queue
'
]
=
settings
.
CELERY_HAYSTACK_QUEUE
if
settings
.
CELERY_HAYSTACK_COUNTDOWN
:
options
[
'
countdown
'
]
=
settings
.
CELERY_HAYSTACK_COUNTDOWN
task
=
get_update_task
()
task
.
apply_async
((
self
.
_queue
,),
{},
**
options
)
def
enqueue
(
self
,
action
,
instance
,
sender
,
**
kwargs
):
def
enqueue
(
self
,
action
,
instance
,
sender
,
**
kwargs
):
"""
"""
Given an individual model instance, determine if a backend
Given an individual model instance, determine if a backend
...
...
This diff is collapsed.
Click to expand it.
celery_haystack/utils.py
+
0
−
29
View file @
4ac097e9
...
@@ -3,7 +3,6 @@ try:
...
@@ -3,7 +3,6 @@ try:
from
importlib
import
import_module
from
importlib
import
import_module
except
ImportError
:
except
ImportError
:
from
django.utils.importlib
import
import_module
from
django.utils.importlib
import
import_module
from
django.db
import
connection
,
transaction
from
.conf
import
settings
from
.conf
import
settings
...
@@ -22,31 +21,3 @@ def get_update_task(task_path=None):
...
@@ -22,31 +21,3 @@ def get_update_task(task_path=None):
raise
ImproperlyConfigured
(
'
Module
"
%s
"
does not define a
"
%s
"
'
raise
ImproperlyConfigured
(
'
Module
"
%s
"
does not define a
"
%s
"
'
'
class.
'
%
(
module
,
attr
))
'
class.
'
%
(
module
,
attr
))
return
task
return
task
def
enqueue_task
(
queue
,
**
kwargs
):
"""
Common utility for enqueing a task for the given action and
model instance.
"""
options
=
{}
if
settings
.
CELERY_HAYSTACK_QUEUE
:
options
[
'
queue
'
]
=
settings
.
CELERY_HAYSTACK_QUEUE
if
settings
.
CELERY_HAYSTACK_COUNTDOWN
:
options
[
'
countdown
'
]
=
settings
.
CELERY_HAYSTACK_COUNTDOWN
task
=
get_update_task
()
task_func
=
lambda
:
task
.
apply_async
((
queue
,),
kwargs
,
**
options
)
if
hasattr
(
transaction
,
'
on_commit
'
):
# Django 1.9 on_commit hook
transaction
.
on_commit
(
task_func
)
elif
hasattr
(
connection
,
'
on_commit
'
):
# Django-transaction-hooks
connection
.
on_commit
(
task_func
)
else
:
task_func
()
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