1

I have setup Celery to run a periodic task every 10 seconds that sends a post request to my Django Rest API Framework.

When I run the Celery worker it picks up the task correctly:

[tasks]
  . FutureForex.celery.debug_task
  . arbitrager.tasks.arb_data_post_request

When I run the beat nothing more gets logged and the POST request is not executed:

[2021-12-10 16:51:24,696: INFO/MainProcess] beat: Starting...

My tasks.py contains the following:

from celery import Celery
from celery.schedules import crontab
from celery.utils.log import get_task_logger

import requests

app = Celery()

logger = get_task_logger(__name__)


@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
    # Calls arb_data_post_request every 10 seconds.
    sender.add_periodic_task(10.0, arb_data_post_request.s(), name='arb_data_post_request')


@app.task
def arb_data_post_request():
    """
    Post request to the Django framework to pull the exchnage data and save to the database
    :return:
    """
    request = requests.post('http://127.0.0.1:8000/arbitrager/data/')
    logger.info(request.text)

I believe Celery is installed and setup correctly, as it finds the task. I can provide any settings if required though. Any ideas as to why it doesn't kick off the task according to the scheduled 10 seconds would be appreciated.

Thanks, Saul

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.