django-background-tasks not working with django-hosts

275 views Asked by At

django-background-tasks package does not work when django-hosts package is configured.

My background task function looks something like this:

@staticmethod
@background(queue="text")
def sendMessage(phone_number, message):

I am running this function on a specific queue.

Also background task command is running too.

python3 manage.py process_tasks --queue text

My hosts configuration works properly. But not background tasks. When I remove hosts configuration background task function executes.

1

There are 1 answers

1
Martin Janeček On BEST ANSWER

Did you set the DEFAULT_HOST setting? Since there's no HTTP request in the CLI/background task, there's no other way to detect the HOST, which could be the cause of your errors.

Also, posting an actual error message with your question would be useful.

Set the DEFAULT_HOST setting to the name of the host pattern you want to refer to as the default pattern. It'll be used if no other pattern matches or you don't give a name to the host_url template tag.