gdgvda / cron

a cron library for go
MIT License
13 stars 3 forks source link

remove Job interface #10

Closed janrnc closed 1 year ago

janrnc commented 1 year ago

Do you think there's a good reason for having a FuncJob type definition for func()? https://github.com/gdgvda/cron/blob/5eb0ef714f0dea726f412d4d57328ba2011f50ae/cron.go#L134

It provides a Run() method which just calls itself. It feels like a simple func() would do the same without additional wrapping. In this way also JobWrapper could be removed, since we could get the same result by simply nesting function calls. https://github.com/gdgvda/cron/blob/5eb0ef714f0dea726f412d4d57328ba2011f50ae/chain.go#L11

janrnc commented 1 year ago

I've dug a bit deeper into this.

FuncJob is adapting func()s to the Job interface. Considering that cron just needs a generic code block to execute, a simple func() should be enough IMO. Closures would help in more complex cases and in general the mapping between cron schedule IDs and the context of the job can be user's responsibility. This way extra complexity is introduced only when it's really necessary.

JobWrapper and Chain may probably be simplified too but I'd like to review those in some next refactor.

See #15