From bcdbf46c8ec8f3daf60550c059693595cc4cff79 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 11 Apr 2013 20:47:37 +0100 Subject: Add timeout feature --- desktop-cronish | 9 ++++++++- tests/timeout.script | 13 +++++++++++++ tests/timeout.stderr | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 tests/timeout.script create mode 100644 tests/timeout.stderr diff --git a/desktop-cronish b/desktop-cronish index f69d16e..738d29c 100755 --- a/desktop-cronish +++ b/desktop-cronish @@ -17,6 +17,7 @@ import cliapp import time +import sys import yaml @@ -68,9 +69,15 @@ class DesktopCronish(cliapp.Application): def execute_job(self, job_name): job = self.jobs[job_name] - exit, out, err = cliapp.runcmd_unchecked(['sh', '-c', job['command']]) + argv = ['sh', '-c', job['command']] + if 'timeout' in job: + argv = ['timeout', str(job['timeout'])] + argv + exit, out, err = cliapp.runcmd_unchecked(argv) self.output.write(out) if exit != 0: + sys.stderr.write( + 'ERROR: Job %s: Command failed: %s\n' % + (job_name, ' '.join(argv))) sys.stderr.write(err) self.previously[job_name] = self.now() diff --git a/tests/timeout.script b/tests/timeout.script new file mode 100755 index 0000000..0533880 --- /dev/null +++ b/tests/timeout.script @@ -0,0 +1,13 @@ +#!/bin/sh + +set -eu + +cat < "$DATADIR/foo.tasks" +date: + interval: 2 + timeout: 1 + command: sleep 1000 +EOF + + +./desktop-cronish --max-jobs=1 "$DATADIR/foo.tasks" diff --git a/tests/timeout.stderr b/tests/timeout.stderr new file mode 100644 index 0000000..a6741f6 --- /dev/null +++ b/tests/timeout.stderr @@ -0,0 +1 @@ +ERROR: Job date: Command failed: timeout 1 sh -c sleep 1000 -- cgit v1.2.1