diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-04-20 11:25:03 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-04-20 11:25:03 +0100 |
commit | 389f0a3d444e113b3ca36baa72306b404f1ae6f4 (patch) | |
tree | 29e777706f11532339baab061c03e689067974f8 /desktop-cronish | |
parent | 963664a6d980a4e425e557f766408d23f0de4a32 (diff) | |
download | desktop-cronish-389f0a3d444e113b3ca36baa72306b404f1ae6f4.tar.gz |
Fix trigger-file
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: |