I’m thinking about using NServiceBus scheduled jobs (probably using HangFire) and have a question regarding approach. Is it advisable to have a scheduled job simply send a command to a handler (most likely a local handler) which does the actual work (separation of concern), rather than just simply put the work in the job itself? My “work” involves calling API’s on an application (e.g. have any new orders been placed) and publishing events (OrderPlacedEvent).
Eventually the logic executed will be the same exception to trigger it the job would first send a message.
What is important is what happend when your job/tasks fails? How are you going to deal with recovery? Do you want to retry automatically like by default happens with messages? Not sure how that works for HangFire.
Also, do you allow overlapped execution of jobs? I think HangFire prevents that is the schedule is too tight. With messages they will be processed overlapping if concurrent processing is enabled (which is the default since v6).
Such integration tasks are often orchestrated by sagas. In that case it makes most sense to send a trigger from a job that will execute the saga.
Does that help?
– Ramon