[Tutor] schedulers

Steven D'Aprano steve at pearwood.info
Thu Feb 28 18:13:17 EST 2019


On Thu, Feb 28, 2019 at 02:45:59PM +0000, nathan tech wrote:
> Hi there,
> 
> I recently started working on a backup program, and the one big feature 
> everyone wants in backup programs is the ability to schedule backups, right?
> 
> but I'm thinking, should I do this?
[...]
> Is that wise? Is that how it should be done?

No. You should write your backup program to do backups, and then 
register that program with your operating system's scheduler. I don't 
know what that's called on Windows, but on Linux that would be "cron".

Basically, you have three problems:

1. Perform the backup.

2. Let the user decide when to do the backup.

3. Actually trigger the program to run at the correct time.


Parts 1 and 2 are your job. Number 3 is up to the OS. It will handle all 
the complex problems of clocks changing between jobs, computer reboots 
(what if the computer is off when the job is supposed to run?) etc.

If for some reason you need to write your own scheduler, using a "busy 
loop" where you run a loop continually checking the time is not the 
right answer. (I don't know what the right answer is, I just know that 
the OS has already solved that.)



-- 
Steven


More information about the Tutor mailing list