unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Shepherd timers
@ 2024-03-24 21:20 Ludovic Courtès
  2024-03-25  9:14 ` raingloom
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Ludovic Courtès @ 2024-03-24 21:20 UTC (permalink / raw)
  To: Guix Devel

Hello Guix!

I pushed to the ‘devel’ branch of the Shepherd a new module that
implements “timers” along with ‘herd’ support to display information
about them.

It lets you provide configuration like this one:

--8<---------------cut here---------------start------------->8---
(use-modules (shepherd service timer))

(define timer
  (service '(my-timer)
           #:start (make-timer-constructor
                    (calendar-event #:seconds '(0 7 15 22 30 45))
                    (command '("sh" "-c" "echo Hi from $PWD.; sleep 20; echo done")))
           #:stop (make-timer-destructor)))

(register-services (list timer))
(start-in-the-background '(my-timer))
--8<---------------cut here---------------end--------------->8---

And then ‘my-timer’ invokes the given command at the moments that match
the constraints defined by ‘calendar-event’—in this case any time the
number of seconds is equal to 0, 7, 15, 22, 30, or 45.  You can also
make it every Monday at 9AM etc., as you would expect.

The ‘herd’ command provides details information about the timer:

--8<---------------cut here---------------start------------->8---
$ ./herd -s sock status my-timer
Status of my-timer:
  It is running since 21:09:32 (68 seconds ago).
  Timed service.
  Periodically running: sh -c "echo Hi from $PWD.; sleep 20; echo done".
  Child process: 1814
  It is enabled.
  Provides (my-timer).
  Requires ().
  Will not be respawned.

Recent runs:
  2024-03-24 21:10:04 Process exited successfully.
  2024-03-24 21:10:19 Process exited successfully.
  2024-03-24 21:10:26 Process exited successfully.
  2024-03-24 21:10:34 Process exited successfully.
  2024-03-24 21:10:35 Process terminated with signal 15.

Recent messages:
  2024-03-24 21:10:29 Hi from /home/ludo.

Upcoming timer alarms:
  21:10:45 (in 5 seconds)
  21:11:00 (in 20 seconds)
  21:11:07 (in 27 seconds)
  21:11:15 (in 35 seconds)
  21:11:22 (in 42 seconds)
--8<---------------cut here---------------end--------------->8---

And of course you can do anything you can do with a service: stop it,
unload it, load a replacement, and so on.

Feedback & suggestions welcome!

Ludo’.


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: Shepherd timers
@ 2024-03-31  3:15 Adam Faiz
  2024-03-31  4:07 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
  2024-03-31  4:09 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
  0 siblings, 2 replies; 16+ messages in thread
From: Adam Faiz @ 2024-03-31  3:15 UTC (permalink / raw)
  To: ludo; +Cc: guix-devel

Hi Ludovic,

I want to give my suggestion for the timer support in the Shepherd:

Could the Shepherd depend on mcron for the timer functionality? Since mcron already handles scheduling commands to run at a certain time, there would be no need to reimplement it again.

Mcron would just need to support handling user jobs dynamically, and the Shepherd implementing timers as a simple interface for it.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-05-01 21:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-24 21:20 Shepherd timers Ludovic Courtès
2024-03-25  9:14 ` raingloom
2024-03-28 22:22   ` Ludovic Courtès
2024-03-25 22:47 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-03-28 22:32   ` Ludovic Courtès
2024-04-02 14:23     ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-04-10 14:45       ` Ludovic Courtès
2024-04-14 19:47         ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-04-19 14:35           ` Ludovic Courtès
2024-04-21 21:28             ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-05-01 21:58               ` Ludovic Courtès
2024-04-03  1:08 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-04-10 14:44   ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2024-03-31  3:15 Adam Faiz
2024-03-31  4:07 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-03-31  4:09 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).