I keep getting “connection failed: connection to the server at “127.0.0.1”, port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections” when running my task in production?” This does not happen in local development.
@db_periodic_task(crontab(minute='*/1'), queue='application_expiration')
def parcel_expiration_task():
# current date and time
current_timestamp = timezone.localtime(timezone.now())
# get all event
get_events = Event.objects.order_by('-creation_time').filter(
time_ends__lt=current_timestamp
)
if get_events.exists():
....
I have tried to add a db. connection in the supervisor:
[program: application]
command='...'
user='...'
autostart=true
autorestart=true
redirect_stderr = true
stdout_logfile = '....'
environment=DATABASE_URL="postgresql://username: password@localhost:5432/db_name"
I have also edited the pg_hba.conf file and added the following entry at the end of the file:
host all all 0.0.0.0/0 md5
host all all ::/0 md5