Skip to content

Commit ab2dc32

Browse files
committed
Initial commit
Initial commit Update README.md Update README.md Create schedule.py Update README.md Update schedule.py Update README.md Update README.md Update README.md Update schedule.py Delete schedule.py Update schedule.py Update README.md Update schedule.py Update README.md
0 parents  commit ab2dc32

File tree

3 files changed

+1041
-0
lines changed

3 files changed

+1041
-0
lines changed

LICENSE

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) 2022 Patrick Joy
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: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# micropython-aioschedule
2+
3+
This project is very much a work in progress. Feel free to submit issues/PR's
4+
5+
The concept is to have a simple micropython scheduler that is asynchronous, persistent (tasks are stored in flash and can be reloaded after a reboot/restart).
6+
7+
Based on the python schedule library by dbader https://github.com/dbader/schedule
8+
9+
Python job scheduling for humans. Run Python functions (or any other callable) periodically using a friendly syntax.
10+
11+
- Asycnronous
12+
- A simple to use API for scheduling jobs, made for humans.
13+
- In-process scheduler for periodic jobs. No extra processes needed!
14+
- Persistence, tasks survive reboot/restart
15+
- Tested on MicroPython 1.19
16+
17+
Usage
18+
-----
19+
20+
Requires datetime and functools from micropython-lib
21+
22+
```
23+
Copy schedule.py to your micropython lib directory
24+
```
25+
26+
```python
27+
28+
import schedule
29+
import time
30+
import machine
31+
import uasyncio as asyncio
32+
33+
async def job():
34+
print("I'm working...")
35+
36+
schedule.every(10).seconds.do(job)
37+
schedule.every(10).minutes.do(job)
38+
schedule.every().hour.do(job)
39+
schedule.every().day.at("10:30").do(job)
40+
schedule.every(5).to(10).minutes.do(job)
41+
schedule.every().monday.do(job)
42+
schedule.every().wednesday.at("13:15").do(job)
43+
schedule.every().minute.at(":17").do(job)
44+
45+
async def job_with_argument(name):
46+
print(f"I am {name}")
47+
48+
schedule.every(10).seconds.do(job_with_argument, name="Peter")
49+
50+
async def main_loop():
51+
# Run all outstanding tasks
52+
# Schedule will yield after all tasks have been run
53+
await schedule.run_pending()
54+
55+
# Run any other user code here
56+
57+
# Save schedule to flash
58+
schedule.save_flash()
59+
60+
# Go to sleep until the next task is due
61+
idle_secs = schedule.idle_seconds()
62+
logger.debug(f'Going to sleep for { idle_secs } seconds')
63+
machine.deepsleep(int(idle_secs) * 1000)
64+
65+
# Load schedule from flash
66+
schedule.load_flash()
67+
68+
try:
69+
asyncio.run(main_loop())
70+
except KeyboardInterrupt:
71+
print('Interrupted')
72+
except Exception as e:
73+
print("caught")
74+
print_exception(e)
75+
finally:
76+
asyncio.new_event_loop()
77+
78+
```
79+
```python
80+
# Save schedule to flash
81+
schedule.save_flash()
82+
83+
# Load schedule from flash
84+
schedule.load_flash()
85+
```
86+
87+
Documentation
88+
-------------
89+
90+
TODO
91+
92+
93+
Meta
94+
----
95+
96+
Patrick Joy `[email protected]`
97+
98+
Inspired by Daniel Bader - `@dbader_org <https://twitter.com/dbader_org>`_ - [email protected],
99+
`Adam Wiggins' <https://github.com/adamwiggins>`_ article `"Rethinking Cron" <https://adam.herokuapp.com/past/2010/4/13/rethinking_cron/>`_
100+
and the `clockwork <https://github.com/Rykian/clockwork>`_ Ruby module.
101+
102+
Distributed under the MIT license. See `LICENSE.txt <https://github.com/ThinkTransit/schedule-micropython/blob/master/LICENSE.txt>`_ for more information.
103+
104+
https://github.com/ThinkTransit/schedule-micropython

0 commit comments

Comments
 (0)