-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DjangoJobExecution fail because sometimes EVENT_JOB_EXECUTED fire before EVENT_JOB_SUBMITTED #121
Comments
Not sure we will be able to work around this while agronholm/apscheduler#445 remains unresolved. |
I have installed and tried to use The job runs fine at the scheduled time, but I am getting a FK constraint error on the INFO:apscheduler.executors.default:Running job "hello_name (trigger: date[2020-10-28 15:45:00 EDT], next run at: 2020-10-28 15:45:00 EDT)" (scheduled at 2020-10-28 15:45:00-04:00) |
Same as you guys, postgreSQL, Django 3.1, Python 3.8 and django_apscheduler 0.5.0 `[31/Oct/2020 12:10:35] "POST /sch/add_task/ HTTP/1.1" 201 15 During handling of the above exception, another exception occurred: Traceback (most recent call last): The above exception was the direct cause of the following exception: Traceback (most recent call last): <JobSubmissionEvent (code=32768)> |
This specific issue only seems to occur when jobs are scheduled to be triggered only once (and are therefore immediately removed from the job store by APScheduler). It is probably similar to the issue mentioned in #116, in which case we might be able to resolve the problem by expanding the error handling introduced as part of that fix to the rest of the event listeners as well. |
@jcass77 hi, I'm experiencing the same thing right now. has this been fixed? |
full logs
|
@aprilahijriyan, I don't think that the error that you are seeing is related to this issue. Please log a new issue, and include details on (1) how you are starting the scheduler in your code and (2) how individual jobs are being scheduled. It seems to me that But that does not make sense since we have the |
Describe the bug
Add DjangoJobExecution fail because sometimes EVENT_JOB_EXECUTED fire before EVENT_JOB_SUBMITTED
To Reproduce
Expected behavior
should ignore add DjangoJobExecution.
Screenshots
h (trigger: date[2020-10-19 09:41:34 UTC], next run at: 2020-10-19 09:41:34 UTC)
[19/Oct/2020 09:41:29] "POST /scheduler/hello HTTP/1.1" 200 17
hello
//////////////TZH EVENT_JOB_EXECUTED
/////////////HELLO 2020-10-19 09:41:34.862484
2020-10-19 09:41:29.846453+00:00 2020-10-19 09:41:34.846471+00:00 Executed 0.010432 1603100494.856903 None None
//////////////TZH EVENT_JOB_SUBMITTED
2020-10-19 09:41:29.846453+00:00 2020-10-19 09:41:34.846471+00:00
/////////////HELLO 2020-10-19 09:41:34.939636
2020-10-19 09:41:29.846453+00:00 2020-10-19 09:41:34.846471+00:00 Started execution None None None None
Error notifying listener
Traceback (most recent call last):
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django_apscheduler/models.py", line 156, in atomic_update_or_create
job_execution = DjangoJobExecution.objects.select_for_update().get(
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/query.py", line 429, in get
raise self.model.DoesNotExist(
django_apscheduler.models.DjangoJobExecution.DoesNotExist: DjangoJobExecution matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/connections.py", line 240, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (
wt
.django_apscheduler_djangojobexecution
, CONSTRAINTdjango_apscheduler_djangojobexecution_job_id_daf5090a_fk
FOREIGN KEY (job_id
) REFERENCESdjango_apscheduler_djangojob
(id
))')The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 831, in _dispatch_event
cb(event)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django_apscheduler/jobstores.py", line 50, in handle_submission_event
job_execution = DjangoJobExecution.atomic_update_or_create(
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django_apscheduler/models.py", line 193, in atomic_update_or_create
job_execution = DjangoJobExecution.objects.create(
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/base.py", line 790, in save_base
updated = self._save_table(
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/base.py", line 933, in _do_insert
return manager._insert(
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/query.py", line 1249, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/anaconda2/envs/py3/lib/python3.8/site-packages/MySQLdb/connections.py", line 240, in query
_mysql.connection.query(self, query)
django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (
wt
.django_apscheduler_djangojobexecution
, CONSTRAINTdjango_apscheduler_djangojobexecution_job_id_daf5090a_fk
FOREIGN KEY (job_id
) REFERENCESdjango_apscheduler_djangojob
(id
))')The text was updated successfully, but these errors were encountered: