summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-04-20 11:00:51 +0100
committerLars Wirzenius <liw@liw.fi>2013-04-20 11:00:51 +0100
commit963664a6d980a4e425e557f766408d23f0de4a32 (patch)
tree74e710177ae8097f9607932c975bdbd2b93ca1e8
parent645abeec9da4520c4bf613af86201280c8df74f8 (diff)
downloaddesktop-cronish-963664a6d980a4e425e557f766408d23f0de4a32.tar.gz
First attempt at implementing trigger-file
-rwxr-xr-xdesktop-cronish18
-rwxr-xr-xtests/mtime-new.script2
-rwxr-xr-xtests/mtime-nofile.script2
-rwxr-xr-xtests/mtime-old.script2
4 files changed, 20 insertions, 4 deletions
diff --git a/desktop-cronish b/desktop-cronish
index eb34c6e..70f2e40 100755
--- a/desktop-cronish
+++ b/desktop-cronish
@@ -17,6 +17,7 @@
import cliapp
import logging
+import os
import time
import sys
import ttystatus
@@ -78,10 +79,11 @@ class DesktopCronish(cliapp.Application):
for job_name, job in self.jobs.items():
if 'interval' in job:
job_when = self.when_interval_job(job_name, job)
+ elif 'trigger-file' in job:
+ job_when = self.when_trigger_file_job(job_name, job)
else:
raise cliapp.AppException(
'Unknown job trigger for %s' % job_name)
- job_when = self.previously.get(job_name, 0) + job['interval']
if next_job_name is None or job_when <= next_when:
next_job_name = job_name
next_when = job_when
@@ -90,6 +92,20 @@ class DesktopCronish(cliapp.Application):
def when_interval_job(self, job_name, job):
return self.previously.get(job_name, 0) + job['interval']
+ def when_trigger_file_job(self, job_name, job):
+ filename = job['trigger-file']
+
+ # If file doesn't exist, trigger now.
+ if not os.path.exists(filename):
+ return self.now()
+
+ # If there is no max age for file, but it exists, never trigger.
+ if 'trigger-age' not in job:
+ return -1
+
+ mtime = os.path.getmtime(filename)
+ return mtime + job['trigger-age']
+
def wait_until(self, when, for_what):
while self.now() < when:
seconds = when - self.now()
diff --git a/tests/mtime-new.script b/tests/mtime-new.script
index 0e92b29..2d1f28e 100755
--- a/tests/mtime-new.script
+++ b/tests/mtime-new.script
@@ -11,4 +11,4 @@ date:
EOF
-./desktop-cronish --max-jobs 5 "$DATADIR/foo.tasks"
+./desktop-cronish --quiet --max-jobs 5 "$DATADIR/foo.tasks"
diff --git a/tests/mtime-nofile.script b/tests/mtime-nofile.script
index 9f8bb8c..9a04a71 100755
--- a/tests/mtime-nofile.script
+++ b/tests/mtime-nofile.script
@@ -11,4 +11,4 @@ date:
EOF
-./desktop-cronish --max-jobs 1 "$DATADIR/foo.tasks"
+./desktop-cronish --quiet --max-jobs 1 "$DATADIR/foo.tasks"
diff --git a/tests/mtime-old.script b/tests/mtime-old.script
index d727c78..a14ad25 100755
--- a/tests/mtime-old.script
+++ b/tests/mtime-old.script
@@ -11,4 +11,4 @@ date:
EOF
-./desktop-cronish --max-jobs 5 "$DATADIR/foo.tasks"
+./desktop-cronish --quiet --max-jobs 5 "$DATADIR/foo.tasks"