Commit e4921021 authored by Elouan Martinet's avatar Elouan Martinet
Browse files

Import get_task_logs and flush_task_logs from the new utils modules

This prevents loading loggers needlessly.
parent f9cd15c69a5e
......@@ -30,7 +30,7 @@ from cubicweb.cwctl import CWCTL
from cubicweb_celerytask.entities import sync_task_state
from cw_celerytask_helpers.monitor import MONITOR_KEY
from cw_celerytask_helpers.utils import get_redis_client
from cw_celerytask_helpers.redisutils import get_redis_client
logger = logging.getLogger(__name__)
......
......@@ -27,16 +27,16 @@ from cubicweb.view import EntityAdapter
from cubicweb.predicates import is_instance
from cubicweb.server.hook import DataOperationMixIn, Operation
from cw_celerytask_helpers import filelogger
from cw_celerytask_helpers import fileutils
# CloudWatch and S3 dependencies are optional
try:
from cw_celerytask_helpers import cloudwatchlogger
from cw_celerytask_helpers import cloudwatchutils
except ImportError:
cloudwatchlogger = None
cloudwatchutils = None
try:
from cw_celerytask_helpers import s3logger
from cw_celerytask_helpers import s3utils
except ImportError:
s3logger = None
s3utils = None
from cubicweb_celerytask import STATES, FINAL_STATES
......@@ -202,9 +202,9 @@ class ICeleryTask(EntityAdapter):
@property
def logs(self):
for logger in [cloudwatchlogger, s3logger, filelogger]:
if logger:
logs = logger.get_task_logs(self.task_id)
for utils in [cloudwatchutils, s3utils, fileutils]:
if utils:
logs = utils.get_task_logs(self.task_id)
if logs:
return logs
return b''
......
......@@ -28,16 +28,16 @@ from cubicweb import ConfigurationError
from cubicweb.predicates import is_instance
from cubicweb.server.hook import Hook, DataOperationMixIn, Operation
from cw_celerytask_helpers import filelogger
from cw_celerytask_helpers import fileutils
# CloudWatch and S3 dependencies are optional
try:
from cw_celerytask_helpers import cloudwatchlogger
from cw_celerytask_helpers import cloudwatchutils
except ImportError:
cloudwatchlogger = None
cloudwatchutils = None
try:
from cw_celerytask_helpers import s3logger
from cw_celerytask_helpers import s3utils
except ImportError:
s3logger = None
s3utils = None
class DeleteCeleryTaskOp(DataOperationMixIn, Operation):
......@@ -48,10 +48,10 @@ class DeleteCeleryTaskOp(DataOperationMixIn, Operation):
celery.task.control.revoke(list(tasks), terminate=True,
signal='SIGKILL')
for task_id in tasks:
for logger in [filelogger, cloudwatchlogger, s3logger]:
if logger:
for utils in [fileutils, cloudwatchutils, s3utils]:
if utils:
try:
logger.flush_task_logs(task_id)
utils.flush_task_logs(task_id)
except Exception:
pass
......
......@@ -18,8 +18,8 @@
import gzip
from logilab.common.shellutils import ProgressBar
from cw_celerytask_helpers.filelogger import get_log_filename
from cw_celerytask_helpers.redislogger import get_task_logs, flush_task_logs
from cw_celerytask_helpers.fileutils import get_log_filename
from cw_celerytask_helpers.redisutils import get_task_logs, flush_task_logs
def migrate_task_logs_to_bfss(cnx):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment