agronholm / agronholm/apscheduler

All workers run job when using sqlite3 data store

Ouverte
#959 17 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug
Langage dominant
Python
Étoiles
7.6k
Forks
783
Merge moyen
4 j 8 h
PR mergées (30 j)
5

Description

### Things to check first

- [X] I have checked that my issue does not already have a solution in the [FAQ](https://apscheduler.readthedocs.io/en/master/faq.html)

- [X] I have searched the existing issues and didn't find my bug already reported there

- [X] I have checked that my bug is still present in the latest release

### Version

v4.0.0a5

### What happened?

When using sqlite3 as the data store and redis as the event broker and having several workers running, jobs are executed by all workers.

### How can we reproduce the bug?

job.py
```python
def job(name, *args, **kwargs):
print(name, args, kwargs)
````

scheduler.py
```python
from apscheduler import Scheduler
from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore
from apscheduler.eventbrokers.redis import RedisEventBroker
from job import job

def main():
data_store = SQLAlchemyDataStore(
engine_or_url="sqlite+aiosqlite:////tmp/test.db"
)
event_broker = RedisEventBroker("redis://localhost:6379")

with Scheduler(data_store, event_broker) as sched:
sched.add_job(job, args=("job1", 1, 2, 3), kwargs=dict(a="A"))

if __name__ == "__main__":
main()
```

worker.py
```python
from apscheduler import Scheduler
from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore
from apscheduler.eventbrokers.redis import RedisEventBroker

def main():
data_store = SQLAlchemyDataStore(
engine_or_url="sqlite+aiosqlite:////tmp/test.db"
)
event_broker = RedisEventBroker("redis://localhost:6379")

with Scheduler(data_store, event_broker) as sched:
sched.run_until_stopped()

if __name__ == "__main__":
main()
```

Here is a screenshot of running two workers and scheduling the job four times.

![image](https://github.com/user-attachments/assets/8bcc5613-d4c1-4737-9455-81b279d8c900)

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.