MDeltaX / jobs

A Cronlike job scheduler in Haskell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jobs

With the help of Jobs, you can start, manage and stop asynchronously, periodically running tasks.

It is threadsafe and easy to use.

{-# LANGUAGE OverloadedStrings #-}
import Jobs

Let's acquire a new job scheduler.

> :t new
new :: IO Scheduler
> jobs <- new

Now this, by default is not running. Let's add two jobs to it.

--              job name    interval    IO computation
> register jobs "1beep"     "7s"        $ putStr "\a"
> register jobs "2beep"     "11s"       $ putStr "\a\a"

If you try putStr "\a" by itself you can note that instead of printing out some weird character,
it makes your computer beep. This is perfect for our use case because we can hear what's going on
in an other thread.

We must start the execution of the jobs with the next command, but before that, we must change the clock speed
of the scheduler, because by default it is aimed at slower tasks.

> setInterval   jobs 1
> startExec     jobs

We now heard 3 beeps, because at start the scheduler runs all tasks. From that point, the scheduler will run the task according to the timing we specified:

Example:        Description
3s              Every 3 seconds
5m              Every 5 minutes
2h              Every 2 hours
7d              Every 7 days
2w              Every two weeks

We can stop the execution of task by issuing

> stopExec jobs

More coming soon.

About

A Cronlike job scheduler in Haskell.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 100.0%