Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
ops
jumpserver
Commits
0d0cf045
Commit
0d0cf045
authored
Jan 28, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改日志查看
parent
56a47b6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
55 deletions
+2
-55
signal_handler.py
apps/ops/celery/signal_handler.py
+2
-55
No files found.
apps/ops/celery/signal_handler.py
View file @
0d0cf045
...
...
@@ -7,6 +7,7 @@ from celery import subtask
from
celery.signals
import
(
worker_ready
,
worker_shutdown
,
after_setup_logger
)
from
kombu.utils.encoding
import
safe_str
from
django_celery_beat.models
import
PeriodicTask
from
common.utils
import
get_logger
...
...
@@ -14,6 +15,7 @@ from .decorator import get_after_app_ready_tasks, get_after_app_shutdown_clean_t
from
.logger
import
CeleryTaskFileHandler
logger
=
get_logger
(
__file__
)
safe_str
=
lambda
x
:
x
@worker_ready.connect
...
...
@@ -48,58 +50,3 @@ def add_celery_logger_handler(sender=None, logger=None, loglevel=None, format=No
formatter
=
logging
.
Formatter
(
format
)
handler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
handler
)
# @after_task_publish.connect
# def after_task_publish_signal_handler(sender, headers=None, **kwargs):
# CeleryTask.objects.create(
# id=headers["id"], status=CeleryTask.WAITING, name=headers["task"]
# )
# cache.set(headers["id"], True, 3600)
#
#
# @task_prerun.connect
# def pre_run_task_signal_handler(sender, task_id=None, task=None, **kwargs):
# time.sleep(0.1)
# for i in range(5):
# if cache.get(task_id, False):
# break
# else:
# time.sleep(0.1)
# continue
#
# t = get_object_or_none(CeleryTask, id=task_id)
# if t is None:
# logger.warn("Not get the task: {}".format(task_id))
# return
# now = datetime.datetime.now().strftime("%Y-%m-%d")
# log_path = os.path.join(now, task_id + '.log')
# full_path = os.path.join(CeleryTask.LOG_DIR, log_path)
#
# if not os.path.exists(os.path.dirname(full_path)):
# os.makedirs(os.path.dirname(full_path))
# with transaction.atomic():
# t.date_start = timezone.now()
# t.status = CeleryTask.RUNNING
# t.log_path = log_path
# t.save()
# f = open(full_path, 'w', encoding="utf-8")
# tee = TeeObj(f)
# sys.stdout = tee
# task.log_f = tee
#
#
# @task_postrun.connect
# def post_run_task_signal_handler(sender, task_id=None, task=None, **kwargs):
# t = get_object_or_none(CeleryTask, id=task_id)
# if t is None:
# logger.warn("Not get the task: {}".format(task_id))
# return
# with transaction.atomic():
# t.status = CeleryTask.FINISHED
# t.date_finished = timezone.now()
# t.save()
# task.log_f.flush()
# sys.stdout = task.log_f.origin_stdout
# task.log_f.close()
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