0

I'm working on a project that has the purpose to execute tasks in intervals.

The tasks and it's properties can be configured through the Configuration Website. The data is being stored in the Configuration Database. The Windows-Service loads all the data from the Configuration Database on startup and then executes the tasks correspondingly:

enter image description here

That means that I have to restart my service in order to apply new changes. There are several problems that come along with it:

1. Handling the restart manually or automatically

I could restart the service every time changes have been made, which could be a bit overkill. I could also give the user the "responsibility" to restart the service. My target group aren't some random clients, they're also Sysadmins so they know what to do. I'd still need to mention somehow that there are "unapplied" changes.

2. Knowing when to restart

There's no direct communication between my website and the service. Restarting whenever could mean that it'll stop the service while it's executing a task; obviously not good. I'd somehow need to queue the restart after all ongoing tasks have been finished but I don't know how to realize this in the first place.

8
  • 3
    Change your logic, so you can push "please update your config" and the service loads the new config without the need to restart.
    – Mr Zach
    Nov 23 at 9:11
  • 1
    The answers to all of these seem to be 'it depends' - I Would start by discussing with the users about their preferences -- there's a good chance that sysadmins will be contented with having some manual steps/instructions and controlling this themselves -- perhaps they'll be happy just to have a message appear on their UI to remind them and pointing them to the instructions. Nov 23 at 9:45
  • 1
    There is no question here. Your post boils down to "I have done A. Therefore, B/C is now the case". Yep. Correct assessment. What's the question?
    – Flater
    Nov 23 at 11:28
  • @MrZach Very good suggestion, I might need to look at Windows-Service communication more. Maybe also WCF, even though that might be a bit too much for my project
    – Junes
    Nov 23 at 12:08
  • @BenCottrell I'll talk to them about it. Perhaps a dialog box that includes "Do you want to apply the changes now/ Do you want to restart the service?" will do it. But that might get on their nerves
    – Junes
    Nov 23 at 12:09
1

Other alternatives:

Polling (1)
Read the Task configuration from the database periodically.

Polling (2)
Poll a "flag" in the database that's set when the configuration is changed and, if that flag has changed, then re-read the Task configuration.

Pause/Resume
As well as Stop and Start, Windows Services respond to two other verbs, Pause and Resume.
You could use these to "signal" to the service to re-read the configuration (as part of the Resume processing).
(OK, it has been a while since I did this) but I seem to recall that a 'Pause'd Service can continue to run useful stuff, so you can Pause and Resume without killing the Service entirely.

1
  • 1: Could work however the downside of it is not being able to apply the changes "directly". It depends on how often I want to do it, however considering that changes are mostly being made in bigger time gaps, that might not be the perfect solution. 2: That could work, but I need to hook up some sort of event, otherwise if I just read the database periodically I have the same problem as with polling 1. I haven't thought about pausing yet. Seems like a good idea to do "OnPause" and "OnResume" events!
    – Junes
    Nov 23 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.