Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
search_tips
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
search_tips
Commits
c6446f96
Commit
c6446f96
authored
May 10, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
81071e7f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
0 deletions
+97
-0
_celery.py
_celery.py
+40
-0
__init__.py
search_tips/__init__.py
+2
-0
celery.py
search_tips/celery.py
+24
-0
celery_task_router.py
search_tips/celery_task_router.py
+31
-0
No files found.
_celery.py
0 → 100644
View file @
c6446f96
# !/usr/bin/env python
# encoding=utf-8
from
__future__
import
absolute_import
import
os
# set the default Django settings module for the 'celery' program.
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'physical.settings'
)
import
raven
from
raven.contrib.celery
import
register_signal
,
register_logger_signal
from
celery
import
Celery
from
django.conf
import
settings
class
Celery
(
Celery
):
"""wrap for celery.Celery."""
def
on_configure
(
self
):
# check if sentry settings provided
if
not
settings
.
SENTRY_CELERY_ENDPOINT
:
return
client
=
raven
.
Client
(
settings
.
SENTRY_CELERY_ENDPOINT
)
# register a custom filter to filter out duplicate logs
register_logger_signal
(
client
)
# hook into the Celery error handler
register_signal
(
client
)
app
=
Celery
(
'physical_tasks'
)
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app
.
config_from_object
(
'django.conf:settings'
)
app
.
autodiscover_tasks
(
lambda
:
settings
.
INSTALLED_APPS
)
search_tips/__init__.py
View file @
c6446f96
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
import
pymysql
from
_celery
import
app
as
celery_app
pymysql
.
install_as_MySQLdb
()
\ No newline at end of file
search_tips/celery.py
0 → 100644
View file @
c6446f96
from
__future__
import
absolute_import
,
unicode_literals
import
os
from
celery
import
Celery
from
django.conf
import
settings
# set the default Django settings module for the 'celery' program.
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'search_tips.settings'
)
app
=
Celery
(
'search_tips'
)
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app
.
config_from_object
(
'django.conf:settings'
,
namespace
=
'CELERY'
)
# Load task modules from all registered Django app configs.
app
.
autodiscover_tasks
()
app
.
conf
.
broker_url
=
settings
.
CELERY_BROKER_URL
@app.task
(
bind
=
True
)
def
debug_task
(
self
):
print
(
'Request: {0!r}'
.
format
(
self
.
request
))
search_tips/celery_task_router.py
0 → 100644
View file @
c6446f96
# coding=utf-8
from
__future__
import
unicode_literals
,
print_function
,
absolute_import
from
django.conf
import
settings
import
itertools
import
logging
class
CeleryTaskRouter
(
object
):
queue_task_map
=
{
"tapir-search_tips"
:
[
'injection.data_sync.tasks.write_to_es'
,
]
}
# Map[TaskName, QueueName]
task_queue_map
=
dict
(
itertools
.
chain
.
from_iterable
(
[(
task
,
queue
)
for
task
in
task_list
]
for
(
queue
,
task_list
)
in
queue_task_map
.
items
()
))
def
route_for_task
(
self
,
task
,
args
=
None
,
kwargs
=
None
):
"""
if settings.DEBUG:
return None
if task.startswith("statistic") or task.startswith("api.tasks.export_excel_task"):
return "slow"
"""
queue_name_or_none
=
self
.
task_queue_map
.
get
(
task
)
return
queue_name_or_none
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment