@ -1,4 +1,4 @@
# Copyright (C) 2016 The Sipwise Team - http://sipwise.com
# Copyright (C) 2016 -2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@ -12,15 +12,19 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import os
import structlog
from celery import Celery
from celery . signals import setup_logging
from django_structlog . celery . steps import DjangoStructLogInitStep
# set the default Django settings module for the 'celery' program.
os . environ . setdefault ( " DJANGO_SETTINGS_MODULE " , " repoapi.settings.prod " )
app = Celery ( " repoapi " )
app . steps [ " worker " ] . add ( DjangoStructLogInitStep )
# 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
@ -31,6 +35,56 @@ app.config_from_object("repoapi.conf:settings", namespace="CELERY")
app . autodiscover_tasks ( )
@setup_logging.connect
def receiver_setup_logging ( loglevel , logfile , format , colorize , * * kwargs ) :
logging . config . dictConfig (
{
" version " : 1 ,
" disable_existing_loggers " : False ,
" formatters " : {
" plain_console " : {
" () " : structlog . stdlib . ProcessorFormatter ,
" processor " : structlog . dev . ConsoleRenderer ( ) ,
} ,
} ,
" handlers " : {
" console " : {
" class " : " logging.StreamHandler " ,
" formatter " : " plain_console " ,
}
} ,
" loggers " : {
" django_structlog " : {
" handlers " : [ " console " ] ,
" level " : " INFO " ,
} ,
" repoapi " : {
" handlers " : [ " console " ] ,
" level " : os . getenv ( " DJANGO_LOG_LEVEL " , " INFO " ) ,
} ,
} ,
}
)
structlog . configure (
processors = [
structlog . stdlib . filter_by_level ,
structlog . stdlib . add_logger_name ,
structlog . stdlib . add_log_level ,
structlog . stdlib . PositionalArgumentsFormatter ( ) ,
structlog . processors . StackInfoRenderer ( ) ,
structlog . processors . format_exc_info ,
structlog . processors . UnicodeDecoder ( ) ,
structlog . processors . ExceptionPrettyPrinter ( ) ,
structlog . stdlib . ProcessorFormatter . wrap_for_formatter ,
] ,
context_class = structlog . threadlocal . wrap_dict ( dict ) ,
logger_factory = structlog . stdlib . LoggerFactory ( ) ,
wrapper_class = structlog . stdlib . BoundLogger ,
cache_logger_on_first_use = True ,
)
@app.task ( )
def jbi_parse_hotfix ( jbi_id , path ) :
app . send_task ( " hotfix.tasks.hotfix_released " , args = [ jbi_id , path ] )