Dynamic task scheduler
Project description
ClockParts
Hi there!
I'm the developer of ClockParts. I encountered many problems in multi-threading projects, APIs, microservices, etc. So I created ClockParts to solve these issues. It's simple, compatible with asynchronous operations and threads, and human-readable.
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clockparts-0.1.45.tar.gz
.
File metadata
- Download URL: clockparts-0.1.45.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fce78f8efa5554c52a8e9a35aa2a9fbc188e0ce2166e11c423de678444a192ab |
|
MD5 | 6991045ec984195c3ba266a3fc6c2b74 |
|
BLAKE2b-256 | f31ba48ab9aa7f89f3982dbc5f1b0269680ba444d8f8001e9aa6f82c63eb7209 |
File details
Details for the file clockparts-0.1.45-py3-none-any.whl
.
File metadata
- Download URL: clockparts-0.1.45-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30475638dfd7b4919912b14a270516cf4b7dc5990087f86a508fc837d8472236 |
|
MD5 | b916aea23e380186905a9efab3df9f6d |
|
BLAKE2b-256 | 936d6dbd47fb6d32b249f721b63ffd9ea64718d9699824a6788de29a10101e61 |