Best Practices for Providing Services in Scheduled Tasks
Curious what's the best way to run something every once in a while, according to a provided schedule (a cron schedule, for example).
More precisely, I'm curious about what's the proper way to provide the service. In my head, it would make sense to provide it inside the part that is repeated at a schedule, rather than providing it outside the schedule. But maybe I'm misunderstanding how those things fit together?
Here is a simplified example of the situation, with EnvLive as the services to provide (a MySql client, in particular), a schedule to repeat every 2 days, and
Is this the correct way (providing inside the
Or is that the preferred way (providing the service outside the
I'm asking because in my mind, each time we do the
Is my understanding wrong?
More precisely, I'm curious about what's the proper way to provide the service. In my head, it would make sense to provide it inside the part that is repeated at a schedule, rather than providing it outside the schedule. But maybe I'm misunderstanding how those things fit together?
Here is a simplified example of the situation, with EnvLive as the services to provide (a MySql client, in particular), a schedule to repeat every 2 days, and
myFn, the effectful function I want to see executed every 2 days.Is this the correct way (providing inside the
repeat logic)?
Or is that the preferred way (providing the service outside the
repeat):I'm asking because in my mind, each time we do the
provide, it borrows a connection from the database pool, and then release it automatically, and it would make sense to do so each time the schedule runs, rather than never releasing it.Is my understanding wrong?
