SummaryRefsLogTreeCommitDiffStats
path: root/src/mcron/scripts/mcron.scm
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2021-08-24 00:20:50 -0400
committerDale Mellor <mcron-lsfnyl@rdmp.org>2022-07-07 09:06:57 +0100
commita7a456cd6fab22eab69303a4430edf5501187299 (patch)
tree914f70b7e4eb924dcfebb5d67cf1c8d47e17f61b /src/mcron/scripts/mcron.scm
parent9e994909255e68b00356ce41e82c6c5dfc98e475 (diff)
downloadmcron-a7a456cd6fab22eab69303a4430edf5501187299.tar.gz
mcron-a7a456cd6fab22eab69303a4430edf5501187299.tar.bz2
mcron-a7a456cd6fab22eab69303a4430edf5501187299.zip
base: Annotate output with job information.
Before this change, it was difficult to discern which job emitted which output, as there was no information connecting the job to the output it produced. This change rectifies that by annotating each line output by cron/mcron with a prefix that contains a timestamp and the job name. It also reports about when the job runs and whether it completed successfully or failed. It was initially suggested here: <https://issues.guix.gnu.org/36510>. Thanks to the fine people from the #guile libera.chat IRC channel for providing ideas and help; this change would not have been possible without them! * src/mcron/base.scm (install-suspendable-ports!): Install suspendable ports. (%date-format, %log-format): New parameters. (validate-date-format, validate-log-format): New procedures. (<job-data>): New record. (run-job): Update doc. Redirect stdout and stderr to a pipe. Return a <job-data> instance containing the input port and other information about the job. Output job status messages. (process-output): New procedure. (child-cleanup): Add docstring. Use positive logic. Call 'process-output' one last time after a child process is collected. (run-job-loop): Add a CHILDREN-DATA variable to the loop. Provide the open file descriptors of the children ports to select*, and collect their output when they trigger select. * tests/base.scm ("run-job: basic"): Adjust and fix indentation. (dummy-job/capture-output): New procedure. ("run-job, output"): New test. ("validate-date-format, valid", "validate-date-format, invalid") ("validate-log-format, valid", "validate-log-format, invalid") ("run-job, output with custom format", "run-job, failure") ("run-job, failure in shell action"): New tests. * src/mcron/scripts/cron.scm (show-help): Document new options. (%options) [log-format, date-format]: New options. (main): Parameterize the main loop with the new parameter options (or their default values when not provided); move exception handling elsewhere (see below). * src/mcron/scripts/mcron.scm: Likewise. * src/cron.in: Install error handler here. * src/mcron.in: Likewise. * doc/mcron.texi: Document new cron and mcron options, as well as new (mcron base) APIs. * tests/basic.sh: Test the new options. Suggested-by: Robert Vollmert <rob@vllmrt.net>
Diffstat (limited to 'src/mcron/scripts/mcron.scm')
-rw-r--r--src/mcron/scripts/mcron.scm20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/mcron/scripts/mcron.scm b/src/mcron/scripts/mcron.scm
index a6b1fa2..300aad0 100644
--- a/src/mcron/scripts/mcron.scm
+++ b/src/mcron/scripts/mcron.scm
@@ -1,6 +1,7 @@
;;;; mcron -- run jobs at scheduled times
;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;;
;;; This file is part of GNU Mcron.
;;;
@@ -41,6 +42,8 @@ standard input), or use all the files in ~/.config/cron (or the deprecated
-i, --stdin=(guile|vixie) Format of data passed as standard input
(default guile)
-s, --schedule[=N] Display the next N (or 8) jobs that will be run
+ --log-format=FMT (ice-9 format) format string for log messages
+ --date-format=FMT (srfi srfi-19) date format string for log messages
-?, --help Give this help list
-V, --version Print program version
@@ -119,6 +122,8 @@ directory. Double-check the folder and file permissions and syntax."))))
(string=? in "vixie")))))
(schedule (single-char #\s) (value optional)
(predicate ,string->number))
+ (log-format (value #t) (predicate ,validate-log-format))
+ (date-format (value #t) (predicate ,validate-date-format))
(help (single-char #\?))
(version (single-char #\V))))))
@@ -141,14 +146,7 @@ directory. Double-check the folder and file permissions and syntax."))))
((0) (setsid))
(else (exit 0)))))
- ;; Forever execute the 'run-job-loop', and when it drops out (can only be
- ;; because a message has come in on the socket) we process the socket
- ;; request before restarting the loop again.
- (catch-mcron-error
- (let ((fdes-list '()))
- (while #t
- (run-job-loop fdes-list)
- ;; we can also drop out of run-job-loop because of a SIGCHLD,
- ;; so must test FDES-LIST.
- (unless (null? fdes-list)
- (process-update-request fdes-list)))))))
+ (parameterize
+ ((%log-format (option-ref options 'log-format (%log-format)))
+ (%date-format (option-ref options 'date-format (%date-format))))
+ (run-job-loop))))