Skip to main content

Thư viện Schedule trên ngôn ngữ Python để chạy service background.

Copyright: MobioVN

CHANGE LOG:

v1.0.1

  • Support Redis cluster

v1.0.0

  • Breaking change:
    • Core concept của phiên bản này là các schedule có thể chạy song song nhằm giải quyết các bài toán như xử lý import excel, csv đồng thời.
    • Để tránh N schedule cùng xử lý 1 file, call self.check_job_allow_running(str_job_id) để check xem job đấy trong 5seconds vừa qua đã có được worker nào xử lý hay không?
    • Giải thuật ở đây là tận dụng Atomic của redis, sử dụng incrby function để check redis-key đã tồn tại chưa? chỉ có worker thao tác incrby đầu tiên(return value = 1) mới có quyền xử lý file

v0.6.7

  • Sửa lỗi key "last_run"

Cài đặt:

$ pip3 install m-schedule

Sử dụng:

  1. Tạo class thực thi scheduler kế thừa từ class BaseScheduler

    class TestScheduler(BaseScheduler):
        def owner_do(self):
            lst_job = db.excel_file.find({"status":0}).limit(1)
            for job in lst_job:
                if self.check_job_allow_running(str(job.id)):
                    print("execute {}".format(job.id))
                else:
                    print("job {} is running".format(job.id))
            pass
    
        def get_schedule(self):
            """
            hàm xác định thời điểm chạy của scheduler, bằng cách xử dụng thư viện schedule
            Các ví dụ hướng dẫn cách xác định thời gian chạy
            1. scheduler chỉ thực hiện công việc một lần duy nhất.
                return None
            2. scheduler sẽ thực hiện mỗi 10 phút một lần.
                return schedule.every(10).minutes
            3. scheduler sẽ thực hiện hàng ngày vào lúc 10h 30 phút.
                return schedule.every().day.at("10:30")
            4. scheduler sẽ thực hiện sau mỗi giờ.
                return schedule.every().hour
            5. scheduler sẽ thực hiện vào mỗi thứ 2 hàng tuần.
                return schedule.every().monday
            6. scheduler sẽ thực hiện vào mỗi thứ 5 hàng tuần và vào lúc 13h 15'.
                return schedule.every().wednesday.at("13:15")
            """
        return schedule.every(10).minutes
    
  2. Đăng ký scheduler với factory

    factory = SchedulerFactory()
    factory.add(TestScheduler(name="MyScheduler", redis_uri="redis://redis-server:6379/0"))
    # sample using redis cluster
    factory.add(TestScheduler(name="MyScheduler1", redis_cluster_uri="redis://redis-cluster.redis.svc.cluster.local:6379/0", redis_type=RedisType.REPLICA))
    factory.run()
    

Metadata

Release files for m-schedule 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for m-schedule 1.0.1
File Size Uploaded Provenance
m-schedule-1.0.1.tar.gz 3.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for m-schedule 1.0.1
File Interpreter ABI Platform
m_schedule-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / m-schedule-1.0.1.tar.gz

Download URL m-schedule-1.0.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e1b4f51beaa428fc109baa932684196e576a56ca5d63a639463d55798c452396
BLAKE2b-256 checksum
How to use checksums
f19454aa7b2675ad8bb2d00337a6d14a98a14faa32872568d12f49cfe1f169ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

Release files / m_schedule-1.0.1-py3-none-any.whl

Download URL m_schedule-1.0.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19ad7d1d5f8f6f0919102b47ef6cfb8a806ba9ff856a64d7b93f911029e08c34
BLAKE2b-256 checksum
How to use checksums
261acf560f437745df94172d6965ec94a3b8ea5fc3db72a5be14090705aad2ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

Security for m-schedule 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page