From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 36875@debbugs.gnu.org
Subject: [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs.
Date: Thu, 01 Aug 2019 09:27:45 +0900 [thread overview]
Message-ID: <875znhbugu.fsf@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 259 bytes --]
Hello!
This follows up to my second post under the thread at
(https://lists.gnu.org/archive/html/help-guix/2019-07/msg00180.html).
It aims to shed some light on (more) complex mcron job Guile scripting
with the aid of Guix features (such as program-file).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-doc-Document-the-use-of-program-file-for-mcron-jobs.patch --]
[-- Type: text/x-patch, Size: 2283 bytes --]
From 4d2c5929f056e547b6bd138f69bd1e09e7cfc89f Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Thu, 1 Aug 2019 07:34:17 +0900
Subject: [PATCH] doc: Document the use of `program-file' for mcron jobs.
* doc/guix.texi (Scheduled Job Execution): Explain why using `program-file'
for an mcron job can be necessary. Add an example.
---
doc/guix.texi | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/doc/guix.texi b/doc/guix.texi
index e6047a4909..418dbce16b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12444,6 +12444,41 @@ gexps to introduce job definitions that are passed to mcron
%base-services)))
@end lisp
+For more complex jobs defined in Scheme, it is safer to pass the job as a
+script to mcron; otherwise, imported syntax definitions wouldn't work
+correctly, as these must be strictly imported at the top level of a Guile
+module. This can be achieved using the @code{program-file} procedure from the
+@code{(guix gexp)} module, as shown in the example below.
+
+@lisp
+(define %battery-alert-job
+ ;; Beep the system when the battery reaches %MIN-LEVEL or less
+ ;; battery percent.
+ #~(job
+ '(next-minute (range 0 60 1))
+ #$(program-file
+ "battery-alert.scm"
+ (with-imported-modules (source-module-closure
+ '((guix build utils)))
+ #~(begin
+ (define %min-level 20)
+ (use-modules (guix build utils)
+ (ice-9 popen)
+ (ice-9 regex)
+ (ice-9 textual-ports)
+ (srfi srfi-26))
+ (setenv "LC_ALL" "C")
+ (let* ((input-pipe (open-pipe* OPEN_READ
+ #$(file-append acpi "/bin/acpi")))
+ (output (get-string-all input-pipe))
+ (m (string-match "Discharging, ([0-9]+)%" output))
+ (level (and=> m (compose string->number
+ (cut match:substring <> 1)))))
+ (when (and=> level (cut <= <> %min-level))
+ (format #t "warning: Battery level is low (~a%)~%" level)
+ (invoke #$(file-append beep "/bin/beep") "-r5"))))))))
+@end lisp
+
@xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
for more information on mcron job specifications. Below is the
reference of the mcron service.
--
2.21.0
[-- Attachment #1.3: Type: text/plain, Size: 16 bytes --]
Thanks,
Maxim
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next reply other threads:[~2019-07-31 15:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 0:27 Maxim Cournoyer [this message]
2019-07-31 19:39 ` [bug#36875] [PATCH] doc: Document the use of `program-file' for mcron jobs Ricardo Wurmus
2019-08-02 0:03 ` Maxim Cournoyer
2019-08-17 20:06 ` Ludovic Courtès
2019-08-25 22:54 ` bug#36875: " Maxim Cournoyer
2019-08-26 8:30 ` [bug#36875] " Ludovic Courtès
2019-08-27 10:59 ` Maxim Cournoyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875znhbugu.fsf@gmail.com \
--to=maxim.cournoyer@gmail.com \
--cc=36875@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.