You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're discussing the possible callbacks implementation with @foca and thought it'd be nice to get opinions from the rest.
Current implementation
There are currently 3 callbacks in Disc: the first one is an error handling callback, which is global to Disc and is executed whenever an unhandled exception is raised while running a job, the other two are lifecycle callbacks: disc_start and disc_done, those are specific to a job class and executed before and after the perform method respectively.
My proposal
I am really wary of callbacks and I particularly dislike things that promote an overly composable callback style as they are easy to abuse and it becomes common to not have any idea of what is going on in a particular piece of code when using them, the intent of the current implementation is to be able to easily share callbacks between groups of jobs via mixins, for example.
So what I've been thinking is: why not just limit lifecycle callbacks to be global like the error handling one? That way all you need to do in order to know what's going on in a job is to look at the job itself and the disc_init file, moreover: the use cases we've been thinking about for these callbacks are about logging and metrics, stuff that you would want to define globally.
So I think having something like Disc.on_start and Disc.on_done (naming not necessarily that) would be nicer, it is of course a bit more limited, but it would allow for the use cases we're considering and enforce that things either happen there or on perform methods, which should make things easier to reason about.
Anyway, we wanted to open up the discussion and hear your thoughts. Any opinions are appreciated. :)
The text was updated successfully, but these errors were encountered:
We're discussing the possible callbacks implementation with @foca and thought it'd be nice to get opinions from the rest.
Current implementation
There are currently 3 callbacks in Disc: the first one is an error handling callback, which is global to Disc and is executed whenever an unhandled exception is raised while running a job, the other two are lifecycle callbacks: disc_start and disc_done, those are specific to a job class and executed before and after the
perform
method respectively.My proposal
I am really wary of callbacks and I particularly dislike things that promote an overly composable callback style as they are easy to abuse and it becomes common to not have any idea of what is going on in a particular piece of code when using them, the intent of the current implementation is to be able to easily share callbacks between groups of jobs via mixins, for example.
So what I've been thinking is: why not just limit lifecycle callbacks to be global like the error handling one? That way all you need to do in order to know what's going on in a job is to look at the job itself and the
disc_init
file, moreover: the use cases we've been thinking about for these callbacks are about logging and metrics, stuff that you would want to define globally.So I think having something like
Disc.on_start
andDisc.on_done
(naming not necessarily that) would be nicer, it is of course a bit more limited, but it would allow for the use cases we're considering and enforce that things either happen there or on perform methods, which should make things easier to reason about.Anyway, we wanted to open up the discussion and hear your thoughts. Any opinions are appreciated. :)
The text was updated successfully, but these errors were encountered: