Linked Questions

Popular Questions

I have an app that uses APScheduler to execute jobs and the interval of a job being executed is 8 days.

It was working fine for the first 2 weeks, but on the next scheduled run time, all the jobs had the same error. From what I could tell, they seem to have lost connection to the database, although nothing has been changed. I get this error:

Job "auto (trigger: interval[8 days, 0:00:00], next run at: 2023-08-22 23:29:16 UTC)" raised an exception Traceback (most recent call last): File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/base/base.py", line 308, in _cursor return self._prepare_cursor(self.create_cursor(name)) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 330, in create_cursor cursor = self.connection.cursor() ^^^^^^^^^^^^^^^^^^^^^^^^ psycopg2.InterfaceError: connection already closed

Because of the error above, the program then produces the following error:

Traceback (most recent call last): File "/workspace/.heroku/python/lib/python3.11/site-packages/apscheduler/executors/base.py", line 125, in run_job retval = job.func(*job.args, **job.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/main/automate.py", line 7, in auto client = Client.objects.get(CLIENT_ID = client_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/query.py", line 633, in get num = len(clone) ^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/query.py", line 380, in self._fetch_all() File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/query.py", line 1881, in _fetch_all self._result_cache = list(self._iterable_class(self)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/query.py", line 91, in iter results = compiler.execute_sql( ^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1560, in execute_sql cursor = self.connection.cursor() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/base/base.py", line 330, in cursor return self._cursor() ^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/base/base.py", line 307, in _cursor with self.wrap_database_errors: File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/base/base.py", line 308, in _cursor return self._prepare_cursor(self.create_cursor(name)) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/workspace/.heroku/python/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 330, in create_cursor cursor = self.connection.cursor() ^^^^^^^^^^^^^^^^^^^^^^^^ django.db.utils.InterfaceError: connection already closed`

Any time a job is about to be run, this error appears. When I access the database on my machine and add a job, it executes normally, so I don't know why there is a change in behavior. How can I resolve the error?

Related Questions