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
6f2a33ab
Commit
6f2a33ab
authored
4 years ago
by
Restyled.io
Browse files
Options
Downloads
Patches
Plain Diff
Restyled by yapf
parent
2660ce77
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
celery_haystack/conf.py
+8
-11
8 additions, 11 deletions
celery_haystack/conf.py
celery_haystack/tasks.py
+23
-25
23 additions, 25 deletions
celery_haystack/tasks.py
with
31 additions
and
36 deletions
celery_haystack/conf.py
+
8
−
11
View file @
6f2a33ab
...
...
@@ -49,10 +49,10 @@ class CeleryHaystack(AppConf):
data
=
{}
for
name
,
value
in
self
.
configured_data
.
items
():
if
name
in
(
"
RETRY_DELAY
"
,
"
MAX_RETRIES
"
,
"
COMMAND_WORKERS
"
,
"
COMMAND_VERBOSITY
"
,
"
RETRY_DELAY
"
,
"
MAX_RETRIES
"
,
"
COMMAND_WORKERS
"
,
"
COMMAND_VERBOSITY
"
,
):
value
=
int
(
value
)
data
[
name
]
=
value
...
...
@@ -61,11 +61,8 @@ class CeleryHaystack(AppConf):
signal_processor
=
getattr
(
settings
,
"
HAYSTACK_SIGNAL_PROCESSOR
"
,
None
)
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.
"
)
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/tasks.py
+
23
−
25
View file @
6f2a33ab
...
...
@@ -28,9 +28,8 @@ class CeleryHaystackSignalHandler(Task):
bits
=
identifier
.
split
(
"
.
"
)
if
len
(
bits
)
<
2
:
logger
.
error
(
"
Unable to parse object
"
"
identifer
'
%s
'
. Moving on...
"
%
identifier
)
logger
.
error
(
"
Unable to parse object
"
"
identifer
'
%s
'
. Moving on...
"
%
identifier
)
return
(
None
,
None
)
pk
=
bits
[
-
1
]
...
...
@@ -48,7 +47,8 @@ class CeleryHaystackSignalHandler(Task):
model_class
=
apps
.
get_model
(
app_name
,
classname
)
if
model_class
is
None
:
raise
ImproperlyConfigured
(
"
Could not load model
'
%s
'
.
"
%
object_path
)
raise
ImproperlyConfigured
(
"
Could not load model
'
%s
'
.
"
%
object_path
)
return
model_class
def
get_instance
(
self
,
model_class
,
pk
,
**
kwargs
):
...
...
@@ -59,14 +59,11 @@ class CeleryHaystackSignalHandler(Task):
try
:
instance
=
model_class
.
_default_manager
.
get
(
pk
=
pk
)
except
model_class
.
DoesNotExist
:
logger
.
error
(
"
Couldn
'
t load %s.%s.%s. Somehow it went missing?
"
%
(
model_class
.
_meta
.
app_label
.
lower
(),
model_class
.
_meta
.
object_name
.
lower
(),
pk
,
)
)
logger
.
error
(
"
Couldn
'
t load %s.%s.%s. Somehow it went missing?
"
%
(
model_class
.
_meta
.
app_label
.
lower
(),
model_class
.
_meta
.
object_name
.
lower
(),
pk
,
))
except
model_class
.
MultipleObjectsReturned
:
logger
.
error
(
"
More than one object with pk %s. Oops?
"
%
pk
)
return
instance
...
...
@@ -76,14 +73,14 @@ class CeleryHaystackSignalHandler(Task):
Fetch the model
'
s registered ``SearchIndex`` in a standarized way.
"""
try
:
using_backends
=
connection_router
.
for_write
(
**
{
"
models
"
:
[
model_class
]})
using_backends
=
connection_router
.
for_write
(
**
{
"
models
"
:
[
model_class
]})
for
using
in
using_backends
:
index_holder
=
connections
[
using
].
get_unified_index
()
yield
index_holder
.
get_index
(
model_class
),
using
except
IndexNotFoundException
:
raise
ImproperlyConfigured
(
"
Couldn
'
t find a SearchIndex for %s.
"
%
model_class
)
raise
ImproperlyConfigured
(
"
Couldn
'
t find a SearchIndex for %s.
"
%
model_class
)
def
run
(
self
,
action
,
identifier
,
**
kwargs
):
"""
...
...
@@ -100,9 +97,10 @@ class CeleryHaystackSignalHandler(Task):
# Then get the model class for the object path
model_class
=
self
.
get_model_class
(
object_path
,
**
kwargs
)
for
current_index
,
using
in
self
.
get_indexes
(
model_class
,
**
kwargs
):
current_index_name
=
"
.
"
.
join
(
[
current_index
.
__class__
.
__module__
,
current_index
.
__class__
.
__name__
]
)
current_index_name
=
"
.
"
.
join
([
current_index
.
__class__
.
__module__
,
current_index
.
__class__
.
__name__
])
if
action
==
"
delete
"
:
# If the object is gone, we'll use just the identifier
...
...
@@ -113,16 +111,15 @@ class CeleryHaystackSignalHandler(Task):
logger
.
exception
(
exc
)
self
.
retry
(
exc
=
exc
)
else
:
msg
=
"
Deleted
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
msg
=
"
Deleted
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
logger
.
debug
(
msg
)
elif
action
==
"
update
"
:
# and the instance of the model class with the pk
instance
=
self
.
get_instance
(
model_class
,
pk
,
**
kwargs
)
if
instance
is
None
:
logger
.
debug
(
"
Failed updating
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
)
logger
.
debug
(
"
Failed updating
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
))
raise
ValueError
(
"
Couldn
'
t load object
'
%s
'"
%
identifier
)
# Call the appropriate handler of the current index and
...
...
@@ -133,7 +130,8 @@ class CeleryHaystackSignalHandler(Task):
logger
.
exception
(
exc
)
self
.
retry
(
exc
=
exc
)
else
:
msg
=
"
Updated
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
msg
=
"
Updated
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
logger
.
debug
(
msg
)
else
:
logger
.
error
(
"
Unrecognized action
'
%s
'
. Moving on...
"
%
action
)
...
...
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