Skip to content

Commit 309ca0b

Browse files
committed
Initial commit
0 parents  commit 309ca0b

File tree

7 files changed

+452
-0
lines changed

7 files changed

+452
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.vscode/
2+
*.egg-info/
3+
*.egg/
4+
*.pyc
5+
__pycache__/
6+
build/

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Merlin Zimmerman
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# async_task_scheduler
2+
3+
`async_task_scheduler` is a Python module that allows you to schedule asynchronous tasks using various scheduling strategies such as cron-like schedules, one-time execution, and more.
4+
5+
## Installation
6+
7+
To install the module, simply install it using `pip`:
8+
9+
```sh
10+
pip install async_task_scheduler
11+
```
12+
13+
## Usage
14+
15+
### Creating a Scheduler
16+
17+
First, create an instance of the `Scheduler` class:
18+
19+
```python
20+
from async_task_scheduler import Scheduler
21+
22+
scheduler = Scheduler()
23+
```
24+
25+
### Adding Tasks
26+
27+
You can add tasks to the scheduler using various decorators:
28+
29+
#### Always
30+
31+
Runs the task every minute.
32+
33+
```python
34+
@scheduler.always
35+
async def print_time_every_minute():
36+
print("Cron time:", datetime.now().strftime("%M %H %d %m %w"))
37+
```
38+
39+
#### Cron
40+
41+
Runs the task based on a cron-like schedule.
42+
43+
```python
44+
@scheduler.cron("*/2 * * * *")
45+
async def two_minutes():
46+
print("Every 2 minutes")
47+
```
48+
49+
#### Hourly
50+
51+
Runs the task at the start of every hour.
52+
53+
```python
54+
@scheduler.hourly
55+
async def hourly_task():
56+
print("It is now", datetime.now().strftime("%H:%M"))
57+
```
58+
59+
#### Daily
60+
61+
Runs the task at the start of every day.
62+
63+
```python
64+
@scheduler.daily
65+
async def daily_task():
66+
print("Good morning!")
67+
```
68+
69+
#### Weekly
70+
71+
Runs the task at the start of every week.
72+
73+
```python
74+
@scheduler.weekly
75+
async def weekly_task():
76+
print("This is a weekly task!")
77+
```
78+
79+
#### Monthly
80+
81+
Runs the task at the start of every month.
82+
83+
```python
84+
@scheduler.monthly
85+
async def monthly_task():
86+
print("Welcome to", datetime.now().strftime("%B"))
87+
```
88+
89+
#### At Start
90+
91+
Runs the task once when the scheduler starts.
92+
93+
```python
94+
@scheduler.at_start
95+
async def long_task():
96+
print("Long task starting")
97+
await asyncio.sleep(5)
98+
print("Long task done")
99+
```
100+
101+
#### At Specific Time
102+
103+
Runs the task at a specific datetime.
104+
105+
```python
106+
@scheduler.at(datetime(2025, 3, 10, 18, 29))
107+
async def future_task():
108+
print("This is a task for a specific time.")
109+
```
110+
111+
### Running the Scheduler
112+
113+
To run the scheduler, await the `run` method or call it using `asyncio.run`:
114+
115+
```python
116+
await scheduler.run()
117+
```
118+
119+
or
120+
121+
```python
122+
asyncio.run(scheduler.run())
123+
```
124+
125+
The scheduler will run indefinitely until the program is stopped.
126+
127+
## Example
128+
129+
See the end of the source file for a complete example.
130+
131+
## License
132+
133+
This project is licensed under the MIT License.

0 commit comments

Comments
 (0)