Skip to main content

Dynamic task scheduler

Project description

ClockParts

Hi There 👋!

I'm a developer of ClockParts. I encountered many challenges when working with scheduling tasks in Python, whether in multi-threading projects, APIs, or microservices. So, I created ClockParts to address these issues. It's simple, compatible with asynchronous operations and threads, and human-readable, making scheduling in Python easier and more efficient.

Installation

It's very easy on PyPI:

pip install ClockParts

Usage

This usage is very simple and based on Shaft and Cog. Shaft is the manager of Cog, and Cog represents your tasks.

Project structure:

├── cogs
│   └── my_cogs.py
├── main.py

Shaft

Now, let's see how to create a Shaft:

# main.py
from ClockParts import Shaft
import asyncio

shaft = Shaft()

if __name__ == "__main__":
    # Create a new Shaft
    shaft = Shaft()
    # Add the "cogs" folder (by default it's "cogs")
    shaft.add_cogs("cogs")
    # Run the Shaft
    asyncio.run(shaft.run())

It's simple! Basically, you need an asynchronous context in your project. If you need an internal explanation, in short, it checks every second if there is a new Cog Task to execute.

Cogs

Let's move on to your Cogs!

# cogs/my_cogs.py

from ClockParts import Cog
from datetime import timedelta


class MyCog(Cog):
    """Examples of Cog usage"""

    @Cog.task(timedelta(seconds=5))
    async def task1(self):
        """
        Task to be executed after 5 seconds (using timedelta)
        """

        print("Executing task 1")
    
    @Cog.task("thu 10:00")
    async def task3(self):
        """
        Task to be executed every Thursday at 10:00
        """
        print("Executing task 3")

Does it look simple? Yes, indeed! In short, you don't need to import ClockParts, just import Cog and use its methods to schedule tasks. There are two ways to schedule your tasks:

  • String format: Ideal for selecting specific days of the week and month.
  • Timedelta format: Ideal for scheduling tasks at specific times. In most cases, you should use timedelta. Your Cogs are ready! To run your Shaft, you just need to execute main.py, and you're good to go!

If you're contributing to the repository, feel free to open an issue, pull request, or fork. You're welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clockparts-0.1.49.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

clockparts-0.1.49-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file clockparts-0.1.49.tar.gz.

File metadata

  • Download URL: clockparts-0.1.49.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11

File hashes

Hashes for clockparts-0.1.49.tar.gz
Algorithm Hash digest
SHA256 c51ec2d1da4d55c129f367803a4620b88027a60ba19aa2d2af7d07b0f99ef5a5
MD5 6c21604a56c0ce07da43d5d336a890db
BLAKE2b-256 23c5109fad33531f8b3ebf5fb44512eecd75c77eed8d0a5bca45887e809d7579

See more details on using hashes here.

File details

Details for the file clockparts-0.1.49-py3-none-any.whl.

File metadata

  • Download URL: clockparts-0.1.49-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11

File hashes

Hashes for clockparts-0.1.49-py3-none-any.whl
Algorithm Hash digest
SHA256 51e9d4d727eb446e0858aa5cc117b2e1a9a7eb1eda9611273419a60045e68a96
MD5 f395e09deb9d3998ca7cad5e7ad6d3c4
BLAKE2b-256 60706de5c1abaea879cf61d3ed0351ee0eb2bcc0e2c7e5447a8bb352fb119863

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page