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
3aa3624f
Commit
3aa3624f
authored
4 years ago
by
Restyled.io
Browse files
Options
Downloads
Patches
Plain Diff
Restyled by yapf
parent
8ae94b8c
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
celery_haystack/tasks.py
+23
-25
23 additions, 25 deletions
celery_haystack/tasks.py
with
23 additions
and
25 deletions
celery_haystack/tasks.py
+
23
−
25
View file @
3aa3624f
...
@@ -26,9 +26,8 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -26,9 +26,8 @@ class CeleryHaystackSignalHandler(Task):
bits
=
identifier
.
split
(
"
.
"
)
bits
=
identifier
.
split
(
"
.
"
)
if
len
(
bits
)
<
2
:
if
len
(
bits
)
<
2
:
logger
.
error
(
logger
.
error
(
"
Unable to parse object
"
"
Unable to parse object
"
"
identifer
'
%s
'
. Moving on...
"
%
identifier
"
identifer
'
%s
'
. Moving on...
"
%
identifier
)
)
return
(
None
,
None
)
return
(
None
,
None
)
pk
=
bits
[
-
1
]
pk
=
bits
[
-
1
]
...
@@ -46,7 +45,8 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -46,7 +45,8 @@ class CeleryHaystackSignalHandler(Task):
model_class
=
apps
.
get_model
(
app_name
,
classname
)
model_class
=
apps
.
get_model
(
app_name
,
classname
)
if
model_class
is
None
:
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
return
model_class
def
get_instance
(
self
,
model_class
,
pk
,
**
kwargs
):
def
get_instance
(
self
,
model_class
,
pk
,
**
kwargs
):
...
@@ -57,14 +57,11 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -57,14 +57,11 @@ class CeleryHaystackSignalHandler(Task):
try
:
try
:
instance
=
model_class
.
_default_manager
.
get
(
pk
=
pk
)
instance
=
model_class
.
_default_manager
.
get
(
pk
=
pk
)
except
model_class
.
DoesNotExist
:
except
model_class
.
DoesNotExist
:
logger
.
error
(
logger
.
error
(
"
Couldn
'
t load %s.%s.%s. Somehow it went missing?
"
%
(
"
Couldn
'
t load %s.%s.%s. Somehow it went missing?
"
model_class
.
_meta
.
app_label
.
lower
(),
%
(
model_class
.
_meta
.
object_name
.
lower
(),
model_class
.
_meta
.
app_label
.
lower
(),
pk
,
model_class
.
_meta
.
object_name
.
lower
(),
))
pk
,
)
)
except
model_class
.
MultipleObjectsReturned
:
except
model_class
.
MultipleObjectsReturned
:
logger
.
error
(
"
More than one object with pk %s. Oops?
"
%
pk
)
logger
.
error
(
"
More than one object with pk %s. Oops?
"
%
pk
)
return
instance
return
instance
...
@@ -74,14 +71,14 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -74,14 +71,14 @@ class CeleryHaystackSignalHandler(Task):
Fetch the model
'
s registered ``SearchIndex`` in a standarized way.
Fetch the model
'
s registered ``SearchIndex`` in a standarized way.
"""
"""
try
:
try
:
using_backends
=
connection_router
.
for_write
(
**
{
"
models
"
:
[
model_class
]})
using_backends
=
connection_router
.
for_write
(
**
{
"
models
"
:
[
model_class
]})
for
using
in
using_backends
:
for
using
in
using_backends
:
index_holder
=
connections
[
using
].
get_unified_index
()
index_holder
=
connections
[
using
].
get_unified_index
()
yield
index_holder
.
get_index
(
model_class
),
using
yield
index_holder
.
get_index
(
model_class
),
using
except
IndexNotFoundException
:
except
IndexNotFoundException
:
raise
ImproperlyConfigured
(
raise
ImproperlyConfigured
(
"
Couldn
'
t find a SearchIndex for %s.
"
%
"
Couldn
'
t find a SearchIndex for %s.
"
%
model_class
model_class
)
)
def
run
(
self
,
action
,
identifier
,
**
kwargs
):
def
run
(
self
,
action
,
identifier
,
**
kwargs
):
"""
"""
...
@@ -98,9 +95,10 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -98,9 +95,10 @@ class CeleryHaystackSignalHandler(Task):
# Then get the model class for the object path
# Then get the model class for the object path
model_class
=
self
.
get_model_class
(
object_path
,
**
kwargs
)
model_class
=
self
.
get_model_class
(
object_path
,
**
kwargs
)
for
current_index
,
using
in
self
.
get_indexes
(
model_class
,
**
kwargs
):
for
current_index
,
using
in
self
.
get_indexes
(
model_class
,
**
kwargs
):
current_index_name
=
"
.
"
.
join
(
current_index_name
=
"
.
"
.
join
([
[
current_index
.
__class__
.
__module__
,
current_index
.
__class__
.
__name__
]
current_index
.
__class__
.
__module__
,
)
current_index
.
__class__
.
__name__
])
if
action
==
"
delete
"
:
if
action
==
"
delete
"
:
# If the object is gone, we'll use just the identifier
# If the object is gone, we'll use just the identifier
...
@@ -111,16 +109,15 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -111,16 +109,15 @@ class CeleryHaystackSignalHandler(Task):
logger
.
exception
(
exc
)
logger
.
exception
(
exc
)
self
.
retry
(
exc
=
exc
)
self
.
retry
(
exc
=
exc
)
else
:
else
:
msg
=
"
Deleted
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
msg
=
"
Deleted
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
logger
.
debug
(
msg
)
logger
.
debug
(
msg
)
elif
action
==
"
update
"
:
elif
action
==
"
update
"
:
# and the instance of the model class with the pk
# and the instance of the model class with the pk
instance
=
self
.
get_instance
(
model_class
,
pk
,
**
kwargs
)
instance
=
self
.
get_instance
(
model_class
,
pk
,
**
kwargs
)
if
instance
is
None
:
if
instance
is
None
:
logger
.
debug
(
logger
.
debug
(
"
Failed updating
'
%s
'
(with %s)
"
%
"
Failed updating
'
%s
'
(with %s)
"
(
identifier
,
current_index_name
))
%
(
identifier
,
current_index_name
)
)
raise
ValueError
(
"
Couldn
'
t load object
'
%s
'"
%
identifier
)
raise
ValueError
(
"
Couldn
'
t load object
'
%s
'"
%
identifier
)
# Call the appropriate handler of the current index and
# Call the appropriate handler of the current index and
...
@@ -131,7 +128,8 @@ class CeleryHaystackSignalHandler(Task):
...
@@ -131,7 +128,8 @@ class CeleryHaystackSignalHandler(Task):
logger
.
exception
(
exc
)
logger
.
exception
(
exc
)
self
.
retry
(
exc
=
exc
)
self
.
retry
(
exc
=
exc
)
else
:
else
:
msg
=
"
Updated
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
msg
=
"
Updated
'
%s
'
(with %s)
"
%
(
identifier
,
current_index_name
)
logger
.
debug
(
msg
)
logger
.
debug
(
msg
)
else
:
else
:
logger
.
error
(
"
Unrecognized action
'
%s
'
. Moving on...
"
%
action
)
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