Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing UTCTime to Job #31

Open
joehealy opened this issue Feb 7, 2017 · 3 comments
Open

Passing UTCTime to Job #31

joehealy opened this issue Feb 7, 2017 · 3 comments

Comments

@joehealy
Copy link

joehealy commented Feb 7, 2017

Thanks in advance of my request for a really useful scheduling library.

Is there any scope to extend cron so that the time it has been scheduled for is passed to the job?

Ie so the Job definition becomes something like:

data Job = Job CronSchedule (UTCTime -> IO ())

This way, systems relying on cron can be tested independently of the current wall clock time...
I realise this would break plenty of code, but maybe there is a way to add it without doing so?

Maybe something like:

data Job = Job CronSchedule (IO ())
| JobWithTime CronSchedule (UTCTime -> IO ())

I'm using a fork at https://github.com/joehealy/cron/tree/pass_time_to_jobs to achieve this, but without the backwards compatibility.

@MichaelXavier
Copy link
Owner

I'll take a look at this. It would be a shame if we had to break the constructor to enable this functionality. I'm not that familiar with the Job functionality, someone else added it.

@MichaelXavier
Copy link
Owner

Ok how about this: what if we change ScheduleT from:

newtype ScheduleT m a = ScheduleT { unSchedule :: StateT Jobs (ExceptT ScheduleError m) a }

to

data JobState = JobState {
    jobs :: [Job]
 , getTime :: IO UTCTime
}

defJobState :: JobState
defJobState = JobState [] getCurrentTime

newtype ScheduleT m a = ScheduleT { unSchedule :: StateT JobState (ExceptT ScheduleError m) a }

Then if you want to inject your own timer you can, otherwise you use the default. What do you think?

@MichaelXavier
Copy link
Owner

I just realized this doesn't give your jobs the time but it does seem to address the issue of testing independently of wall time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants