agronholm / agronholm/apscheduler

All workers run job when using sqlite3 data store

Đang mở
#959 17 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
7.6k
Fork
783
Merge trung bình
4 ngày 8 giờ
Pull request đã merge (30 ngày)
5

Mô tả

### 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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.