From 4deef2283ce371e0c5e4e3360617e1890dee9cac Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 11 Apr 2013 20:51:09 +0100 Subject: Add logging --- desktop-cronish | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/desktop-cronish b/desktop-cronish index 738d29c..713f135 100755 --- a/desktop-cronish +++ b/desktop-cronish @@ -16,6 +16,7 @@ import cliapp +import logging import time import sys import yaml @@ -40,6 +41,7 @@ class DesktopCronish(cliapp.Application): self.execute_jobs() def process_input(self, filename): + logging.info('Loading jobs from %s' % filename) with self.open_input(filename, 'r') as f: job_dict = yaml.safe_load(f) self.jobs.update(job_dict) @@ -52,6 +54,7 @@ class DesktopCronish(cliapp.Application): self.wait_until(when) self.execute_job(job_name) n += 1 + logging.info('Stopped executing after %d jobs' % n) def choose_job(self): next_job_name = None @@ -65,10 +68,13 @@ class DesktopCronish(cliapp.Application): def wait_until(self, when): while self.now() < when: - time.sleep(when - self.now()) + seconds = when - self.now() + logging.info('Sleeping for %d seconds' % seconds) + time.sleep(seconds) def execute_job(self, job_name): job = self.jobs[job_name] + logging.info('Executing job %s: %s' % (job_name, job['command'])) argv = ['sh', '-c', job['command']] if 'timeout' in job: argv = ['timeout', str(job['timeout'])] + argv @@ -84,4 +90,5 @@ class DesktopCronish(cliapp.Application): def now(self): return time.time() + DesktopCronish(version=__version__).run() -- cgit v1.2.1