I have a celery application and that executes a task with concurrency = 1. I added the log using following code, it is working fine however when it tries to rotate the log i am facing exception,
below is my code,
app = Celery('src.tasks',
broker='amqp://user:pass@server:5672//',
)
app.config_from_object('src.settings')
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_ACKS_LATE=True,
CELERY_PREFETCH_MULTIPLIER=1,
CELERYBEAT_MAX_LOOP_INTERVAL=600,
CELERY_ROUTES={'myqueue': {'queue': 'myqueue'}},
CELERY_TASK_SERIALIZER='pickle',
CELERY_RESULT_SERIALIZER='pickle',
CELERY_ACCEPT_CONTENT=['pickle', 'json'],
result_expires=3600,
)
LOGGER = app.conf.LOGGER
and my setting is,
LOG_FILENAME="log.log"
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME,
maxBytes=100,
backupCount=5,
)
formatter = logging.Formatter(LOG_FORMAT)
handler.setFormatter(formatter)
LOGGER.addHandler(handler)
I am executing the code like below
>> celery -A src.tasks worker -E -Q AWS_jobclassification --concurrency=1
the error
[2020-12-18 06:40:01,305: WARNING/Worker-1] File "d:\install\miniconda\envs\py27\lib\logging\handlers.py", line 350, in doRollover
[2020-12-18 06:40:01,305: WARNING/Worker-1] os.rename(self.baseFilename, dfn)
[2020-12-18 06:40:01,305: WARNING/Worker-1] WindowsError: [Error 32] The process cannot access the file because it is being used by another process
[2020-12-18 06:40:01,305: WARNING/Worker-1] Logged from file tasks.py, line 183
What is wrong in my code ? and how can i use log rotate in celery task ? Thank you.
i am using Windows server