Job Scheduling in Haskell
haskell, job-scheduling
Solution
Why not `forkIO` and `threadDelay`?
Here's a sketch of what you can do:
type JobId = ThreadId
type Job = IO
schedule :: Date -> Job () -> Job JobId
schedule date job =
forkIO $ do
time <- getCurrentTime
threadDelay (delay time)
job
where
delay time = error "TODO: compute the delay from `time` and `date`"
Problem
What work has been done so far in Haskell to the effect of scheduling jobs for execution in a native way? Here's an sketch of what I am thinking. Say I have a function `work` I want executed at `Date`, presumably in the future (if not, we can just schedule it for immediate execution). In this case, let's just pretend there's some kind of `Job` monad for this to occur in. ``` type JobId = .. schedule :: Date -> Job () -> Job JobId ``` This is then passed into a (preferably persistent) scheduling mechanism that will execute the scheduled job at an appropriate time and also provide some kind of reference `JobId` so the job can be inspected or rescheduled. I've used a couple different job scheduling libraries in Ruby, such as Delayed Job and Sidekiq. Is there similar work in the Haskell community on the job scheduling problem? Perhaps with Haskell the nature of the language gives rise to a pattern simple enough, given some primitive functions, a library isn't wholly necessary?