-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks.py
More file actions
23 lines (18 loc) · 679 Bytes
/
Copy pathtasks.py
File metadata and controls
23 lines (18 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import logging
from celery.utils.log import get_task_logger
from celery_config import celery_app
import time
# for debugging purposes
logger = get_task_logger(__name__)
logger.setLevel(logging.INFO) # Set logging level to INFO
handler = logging.FileHandler('my_log.log')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# the task itself
@celery_app.task(name='tasks.apiworld')
def apiworld():
logger.info('Demo task started!')
time.sleep(10) # Simulate a task that takes 10 seconds to complete
logger.info('Demo task completed!')
return 'Demo task completed!'