[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 05/15: scratch: Stub out timeout support.
From: |
Juliana Sims |
Subject: |
[shepherd] 05/15: scratch: Stub out timeout support. |
Date: |
Tue, 26 Nov 2024 13:27:18 -0500 (EST) |
juli pushed a commit to branch wip-goblinsify
in repository shepherd.
commit f4ddf3ad832951b31c0906e401c9bff4a0602571
Author: Juliana Sims <juli@incana.org>
AuthorDate: Thu Oct 10 09:19:20 2024 -0400
scratch: Stub out timeout support.
* scratch.scm (^timeout, &timeout-error): New symbol.
(terminate-process): Use race and ^timeout.
---
scratch.scm | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/scratch.scm b/scratch.scm
index 79d42d4..2cbbe74 100644
--- a/scratch.scm
+++ b/scratch.scm
@@ -40,6 +40,15 @@ it"
(define id
(spawn-named 'id ^pcell val))]))
+;; Thanks to David Thompson for this one
+(define (^timeout bcom)
+ (lambda* (#:key (duration (default-process-termination-grace-period))
+ (value 'timeout))
+ (spawn-fibrous-vow
+ (lambda ()
+ (sleep duration)
+ value))))
+
;;; extant Shepherd utils
(define (remove pred lst)
@@ -55,6 +64,11 @@ it"
;;; porting experiments
+;; Original exceptions
+
+(define-exception-type &timeout-error &external-error
+ make-timeout-error timeout-error?)
+
;; Shepherd uses SRFI-34 and SRFI-35 for exceptions. Let's update those
;; Service errors.
@@ -775,10 +789,10 @@ which its completion status will be sent."
group; wait for @var{pid} to terminate and return its exit status. If
@var{pid} is still running @var{grace-period} seconds after @var{signal} has
been sent, send it @code{SIGKILL}."
- ;; TODO: implement grace-period support
(assert (current-process-monitor))
(catch-system-error (kill pid signal))
- (on (<- (current-process-monitor) 'await (abs pid))
+ (on (race (<- (current-process-monitor) 'await (abs pid))
+ ($ (spawn ^timeout) #:duration grace-period))
(lambda (status)
(if status
status
@@ -812,9 +826,7 @@ process is still running after @var{grace-period} seconds,
send it
(with-vat shepherd-vat
(let ((cl (command-line)))
- (if (> (length cl) 1)
- (primitive-load* (cadr cl))
- (primitive-load* (car cl)))
+ (primitive-load* ((if (> (length cl) 1) cadr car) cl))
(let lp ()
(on (<- (current-registry) 'service-list)
(lambda (lst)
- [shepherd] branch wip-goblinsify created (now 2739fea), Juliana Sims, 2024/11/26
- [shepherd] 03/15: Implement service-registry demo., Juliana Sims, 2024/11/26
- [shepherd] 01/15: .guix-authorizations: Add juli., Juliana Sims, 2024/11/26
- [shepherd] 02/15: Add Goblins port infrastructure., Juliana Sims, 2024/11/26
- [shepherd] 10/15: Add design doc., Juliana Sims, 2024/11/26
- [shepherd] 13/15: Incorporate Spritely feedback into design doc, Juliana Sims, 2024/11/26
- [shepherd] 07/15: scratch: First pass at service startup code., Juliana Sims, 2024/11/26
- [shepherd] 04/15: scratch: Begin prototyping process monitoring., Juliana Sims, 2024/11/26
- [shepherd] 05/15: scratch: Stub out timeout support.,
Juliana Sims <=
- [shepherd] 06/15: scratch: Cleanup comments somewhat., Juliana Sims, 2024/11/26
- [shepherd] 08/15: goblins port manifest: Update dependency commits, fix inputs., Juliana Sims, 2024/11/26
- [shepherd] 11/15: Update design doc., Juliana Sims, 2024/11/26
- [shepherd] 09/15: scratch: Return demo to working state., Juliana Sims, 2024/11/26
- [shepherd] 12/15: Incorporate more feedback into design doc, Juliana Sims, 2024/11/26
- [shepherd] 14/15: dir-locals: Add indentation for Goblins forms., Juliana Sims, 2024/11/26
- [shepherd] 15/15: WIP: shepherd: Port core service actor., Juliana Sims, 2024/11/26