diff options
Diffstat (limited to 'desktop-cronish')
-rwxr-xr-x | desktop-cronish | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/desktop-cronish b/desktop-cronish index 70f2e40..98e78ca 100755 --- a/desktop-cronish +++ b/desktop-cronish @@ -39,6 +39,11 @@ class DesktopCronish(cliapp.Application): self.settings.boolean( ['quiet', 'q'], 'no status messaging to terminal') + + self.settings.integer( + ['sleep'], + 'if there is no known job, sleep for SECONDS', + default=1) def process_args(self, args): self.ts = ttystatus.TerminalStatus(period=0.1) @@ -68,8 +73,14 @@ class DesktopCronish(cliapp.Application): max_jobs = self.settings['max-jobs'] while max_jobs == 0 or n < max_jobs: job_name, when = self.choose_job() - self.wait_until(when, job_name) - self.execute_job(job_name) + if job_name is not None: + self.wait_until(when, job_name) + self.execute_job(job_name) + else: + self.status( + 'No idea what to do, sleeping for %d seconds' % + self.settings['sleep']) + time.sleep(self.settings['sleep']) n += 1 self.status('Stopped executing after %d jobs' % n) @@ -84,9 +95,10 @@ class DesktopCronish(cliapp.Application): else: raise cliapp.AppException( 'Unknown job trigger for %s' % job_name) - if next_job_name is None or job_when <= next_when: - next_job_name = job_name - next_when = job_when + if job_when is not None: + if next_job_name is None or job_when <= next_when: + next_job_name = job_name + next_when = job_when return next_job_name, next_when def when_interval_job(self, job_name, job): @@ -101,10 +113,17 @@ class DesktopCronish(cliapp.Application): # If there is no max age for file, but it exists, never trigger. if 'trigger-age' not in job: - return -1 + return None + # If the file exists and is too old, trigger now. mtime = os.path.getmtime(filename) - return mtime + job['trigger-age'] + if mtime + job['trigger-age'] <= self.now(): + return self.now() + + # Do not trigger now. We can't compute the next time to trigger: + # the file might go missing, or get updated, so we need to test + # it every iteration. + return None def wait_until(self, when, for_what): while self.now() < when: |