Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ire4ever1190/taskman
Simple task scheduler
https://github.com/ire4ever1190/taskman
Last synced: 11 days ago
JSON representation
Simple task scheduler
- Host: GitHub
- URL: https://github.com/ire4ever1190/taskman
- Owner: ire4ever1190
- License: mit
- Created: 2021-06-18T13:32:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T08:47:37.000Z (9 months ago)
- Last Synced: 2024-05-02T02:35:03.971Z (6 months ago)
- Language: Nim
- Size: 59.6 KB
- Stars: 20
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## Taskman
A simple and lightweight async/sync scheduling library for running tasks at certain times.
Supports
- Running on an interval e.g. every 5 minutes, every 2.5 seconds
- Running on a set date
- Run after an amount of time e.g. run after 10 hours
- Run on cron format e.g. `10 4 * * *` (Run on the 10th minute of the 4th hour everyday)Go to the [docs here](https://ire4ever1190.github.io/taskman/taskman.html) for more information and examples
### Installation
Either run `nimble install taskman`
or add `requires "taskman"` to your .nimble file### Examples
Every day get the IP address of the computer
```nim
import std/[httpclient, json]let tasks = newAsyncScheduler()
var ip = ""
tasks.every(1.days) do () {.async.}:
let client = newAsyncHttpClient()
defer: client.close()
ip = client
.getContent("https://httpbin.org/ip")
.parseJson()["origin"]
.getStr()waitFor tasks.start()
```When the client first connects they get added to a queue and after 5 mins they are
allowed to see the actual page
```nim
import src/taskman
import std/asynchttpserver
import std/setslet tasks = newAsyncScheduler()
var allowed: HashSet[string]
proc cb(req: Request) {.async, gcsafe.} =
if req.hostname notin allowed:
# Add the client to the wait list
tasks.wait(5.minutes) do () {.async.}:
# Once the wait is over, allow them in
allowed.incl req.hostname
await req.respond(Http200, "You can join in 5 minutes")
else:
await req.respond(Http200, "Hello again!")# This is NOT how you should be using asyncHttpServer
# This is just a basic example
var server = newAsyncHttpServer()
server.listen 8080.Port
echo "Running on port 8080"
while true:
waitFor server.acceptRequest(cb)
```