From patchwork Sun Jun 1 02:51:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: paul X-Patchwork-Id: 42967 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E278927BC4B; Sun, 1 Jun 2025 03:53:39 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 117E427BC49 for ; Sun, 1 Jun 2025 03:53:39 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uLYp0-0000o4-TI; Sat, 31 May 2025 22:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLYoz-0000nk-Qz for guix-patches@gnu.org; Sat, 31 May 2025 22:53:13 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLYoz-0007X6-DT for guix-patches@gnu.org; Sat, 31 May 2025 22:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=c0mrrjGimQg3m608YSHrWpX7CdedaBO05E2EM3xayG0=; b=oQVRqc8omGUawaSeTdh9peyIDGNjF4NRKPS+1e2Nae37N4HQkxIe3/CVW+D4HOGH/EVf4cJfPGdEgGiVaXEm+uWsh/FfNdHzVumOgQk7+MtMgsTF2psvSdltTk9Q6QU95IrCswmJfRQheuQFaXCsTR0CalY80nU/8Qlk5Ruwnvys6M16BJV1yPGCai+Nm4wLdrmRQnRzx5Hxpt6FegnVpMZ05mPUjv+dBUxIntfIYYHmT6CJIFtK71ADsk/ETIBAuYnNDQVmUNsSGfwAOcN7B0AqNy459YLL3zK3u37ypDCtT3Ad9nXr9GJA9iFVWEEJIKhs7kPYSWTRnoKPlNi5PQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uLYoy-0005sf-UJ; Sat, 31 May 2025 22:53:12 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#76081] [PATCH v11 2/5] gnu: Move with-retries outside dbus-service. Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 01 Jun 2025 02:53:12 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 76081 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 76081@debbugs.gnu.org Cc: Giacomo Leidi , Maxim Cournoyer X-Debbugs-Original-Xcc: Maxim Cournoyer Received: via spool by 76081-submit@debbugs.gnu.org id=B76081.174874635422369 (code B ref 76081); Sun, 01 Jun 2025 02:53:12 +0000 Received: (at 76081) by debbugs.gnu.org; 1 Jun 2025 02:52:34 +0000 Received: from localhost ([127.0.0.1]:34561 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLYoG-0005oU-Dp for submit@debbugs.gnu.org; Sat, 31 May 2025 22:52:33 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:49859) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uLYnN-0005i2-IJ for 76081@debbugs.gnu.org; Sat, 31 May 2025 22:51:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1748746292; bh=c0mrrjGimQg3m608YSHrWpX7CdedaBO05E2EM3xayG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0TRl5mG9aX0EJ3Trtk+jqyIclfLDbfRZQIdMK+VrVu4YqFpowOeI/mgwYxPy+1jd +G1I5+mgN0Lo+pQO9YevESgh0gGMNrL5QzZjEEWnGm/XDLyLFHP3e9Nt88viKxmMt9 +lpyVwujFPeZFu7p7bssc0AUVeAZjN8ESGWH2sG4= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4b91hN4RVgz118h; Sun, 1 Jun 2025 02:51:32 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4b91hN3PCNz1181; Sun, 1 Jun 2025 02:51:32 +0000 (UTC) Date: Sun, 1 Jun 2025 04:51:15 +0200 Message-ID: <21078384fabb96961c84bebee6b05a0ce85ee9b4.1748746278.git.goodoldpaul@autistici.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <8ac2edf51988af974ed0b4cd4ac63da23ce17118.1748746278.git.goodoldpaul@autistici.org> References: <8ac2edf51988af974ed0b4cd4ac63da23ce17118.1748746278.git.goodoldpaul@autistici.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches X-Patchwork-Original-From: Giacomo Leidi via Guix-patches via From: paul Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This patch moves with-retries outside of (gnu build dbus-service) into a more general (gnu build utils) which can be imported without unnecessarily importing dbus related symbols. * gnu/build/dbus-service.scm (sleep,with-retries): Move to... * gnu/build/utils.scm: ...here. * gnu/local.mk: Add gnu/build/utils.scm. * gnu/build/jami-service.scm: Import (gnu build utils). * gnu/services/telephony.scm (jami-account->alist): Format. (jami-shepherd-services): Import (gnu build utils). * gnu/test/messaging.scm (run-ngircd-test): Import (gnu build utils). (run-pounce-test): Import (gnu build utils). * gnu/test/telephony.scm (run-jami-test): Import (gnu build utils) and format. Change-Id: I3c1768f884ca46d0820a801bd0310c2ec8f3da54 --- gnu/build/dbus-service.scm | 39 +++------------------------ gnu/build/jami-service.scm | 1 + gnu/build/utils.scm | 55 ++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + gnu/services/telephony.scm | 9 ++++--- gnu/tests/messaging.scm | 8 +++--- gnu/tests/telephony.scm | 11 ++++---- 7 files changed, 76 insertions(+), 48 deletions(-) create mode 100644 gnu/build/utils.scm diff --git a/gnu/build/dbus-service.scm b/gnu/build/dbus-service.scm index 688afe44c3d..9bbcd457512 100644 --- a/gnu/build/dbus-service.scm +++ b/gnu/build/dbus-service.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021, 2022 Maxim Cournoyer +;;; Copyright © 2025 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,6 +25,7 @@ ;;; Code: (define-module (gnu build dbus-service) + #:use-module (gnu build utils) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) @@ -54,45 +56,10 @@ (define-module (gnu build dbus-service) call-dbus-method dbus-available-services - dbus-service-available? - - with-retries)) + dbus-service-available?)) (define %dbus-query-timeout 2) ;in seconds -;;; Use Fibers' sleep to enable cooperative scheduling in Shepherd >= 0.9.0, -;;; which is required at least for the Jami service. -(define sleep* - (lambda () ;delay execution - (if (resolve-module '(fibers) #f #:ensure #f) - (module-ref (resolve-interface '(fibers)) 'sleep) - (begin - (format #t "Fibers not available -- blocking 'sleep' in use~%") - sleep)))) - -;;; -;;; Utilities. -;;; - -(define-syntax-rule (with-retries n delay body ...) - "Retry the code in BODY up to N times until it doesn't raise an exception nor -return #f, else raise an error. A delay of DELAY seconds is inserted before -each retry." - (let loop ((attempts 0)) - (catch #t - (lambda () - (let ((result (begin body ...))) - (if (not result) - (error "failed attempt" attempts) - result))) - (lambda args - (if (< attempts n) - (begin - ((sleep*) delay) ;else wait and retry - (loop (+ 1 attempts))) - (error "maximum number of retry attempts reached" - (quote body ...) args)))))) - ;;; ;;; Low level wrappers above AC/D-Bus. diff --git a/gnu/build/jami-service.scm b/gnu/build/jami-service.scm index a00785f699b..7c2c48d821a 100644 --- a/gnu/build/jami-service.scm +++ b/gnu/build/jami-service.scm @@ -25,6 +25,7 @@ (define-module (gnu build jami-service) #:use-module (gnu build dbus-service) + #:use-module (gnu build utils) #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) diff --git a/gnu/build/utils.scm b/gnu/build/utils.scm new file mode 100644 index 00000000000..1aa72358bd8 --- /dev/null +++ b/gnu/build/utils.scm @@ -0,0 +1,55 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +;;; Commentary: +;;; +;;; This module contains helpers that could useful to any service. +;;; +;;; Code: + +(define-module (gnu build utils) + #:export (with-retries)) + +;;; Use Fibers' sleep to enable cooperative scheduling in Shepherd >= 0.9.0, +;;; which is required at least for the Jami service. +(define sleep* + (lambda () ;delay execution + (if (resolve-module '(fibers) #f #:ensure #f) + (module-ref (resolve-interface '(fibers)) 'sleep) + (begin + (format #t "Fibers not available -- blocking 'sleep' in use~%") + sleep)))) + +(define-syntax-rule (with-retries n delay body ...) + "Retry the code in BODY up to N times until it doesn't raise an exception nor +return #f, else raise an error. A delay of DELAY seconds is inserted before +each retry." + (let loop ((attempts 0)) + (catch #t + (lambda () + (let ((result (begin body ...))) + (if (not result) + (error "failed attempt" attempts) + result))) + (lambda args + (if (< attempts n) + (begin + ((sleep*) delay) ;else wait and retry + (loop (+ 1 attempts))) + (error "maximum number of retry attempts reached" + (quote body ...) args)))))) diff --git a/gnu/local.mk b/gnu/local.mk index 2948bfb1bff..4500bfc6d33 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -841,6 +841,7 @@ GNU_SYSTEM_MODULES = \ %D%/build/linux-modules.scm \ %D%/build/marionette.scm \ %D%/build/secret-service.scm \ + %D%/build/utils.scm \ \ %D%/tests.scm \ %D%/tests/audio.scm \ diff --git a/gnu/services/telephony.scm b/gnu/services/telephony.scm index 9926f4107de..ad6959e161b 100644 --- a/gnu/services/telephony.scm +++ b/gnu/services/telephony.scm @@ -210,7 +210,7 @@ (define (jami-account->alist jami-account-object) (tfilter-maybe-value jami-account-object) (tmap (lambda (field) (let* ((name (field-name->account-detail - (configuration-field-name field))) + (configuration-field-name field))) (value ((configuration-field-serializer field) name ((configuration-field-getter field) jami-account-object)))) @@ -360,7 +360,8 @@ (define (jami-shepherd-services config) ;; variant of the 'sleep' procedure. guile-fibers) (with-imported-modules (source-module-closure - '((gnu build dbus-service) + '((gnu build utils) + (gnu build dbus-service) (gnu build jami-service) (gnu system file-systems))) @@ -541,7 +542,8 @@ (define (jami-shepherd-services config) (list (shepherd-service (documentation "Run a D-Bus session for the Jami daemon.") (provision '(jami-dbus-session)) - (modules `((gnu build dbus-service) + (modules `((gnu build utils) + (gnu build dbus-service) (gnu build jami-service) (gnu system file-systems) ,@%default-modules)) @@ -587,6 +589,7 @@ (define (jami-shepherd-services config) (ice-9 receive) (srfi srfi-1) (srfi srfi-26) + (gnu build utils) (gnu build dbus-service) (gnu build jami-service) (gnu system file-systems) diff --git a/gnu/tests/messaging.scm b/gnu/tests/messaging.scm index 8df67433a7f..2eb99331b52 100644 --- a/gnu/tests/messaging.scm +++ b/gnu/tests/messaging.scm @@ -269,7 +269,7 @@ (define (run-ngircd-test) (marionette-operating-system %ngircd-os #:imported-modules (source-module-closure - '((gnu build dbus-service) + '((gnu build utils) (guix build utils) (gnu services herd))))))) @@ -298,7 +298,7 @@ (define (run-ngircd-test) (test-assert "basic irc operations function as expected" (marionette-eval '(begin - (use-modules ((gnu build dbus-service) #:select (with-retries)) + (use-modules (gnu build utils) (ice-9 textual-ports)) (define (write-command command) @@ -437,7 +437,7 @@ (define (run-pounce-test) (marionette-operating-system %pounce-os #:imported-modules (source-module-closure - '((gnu build dbus-service) + '((gnu build utils) (guix build utils) (gnu services herd))))) (memory-size 1024))) @@ -470,7 +470,7 @@ (define (run-pounce-test) (test-assert "pounce functions as an irc bouncer" (marionette-eval '(begin - (use-modules ((gnu build dbus-service) #:select (with-retries)) + (use-modules (gnu build utils) (guix build utils) (ice-9 textual-ports)) diff --git a/gnu/tests/telephony.scm b/gnu/tests/telephony.scm index f03ea963f7e..3a085762323 100644 --- a/gnu/tests/telephony.scm +++ b/gnu/tests/telephony.scm @@ -143,7 +143,8 @@ (define* (run-jami-test #:key provisioning? partial?) #:imported-modules '((gnu services herd) (guix combinators) (gnu build jami-service) - (gnu build dbus-service)))) + (gnu build dbus-service) + (gnu build utils)))) (define vm (virtual-machine (operating-system os) (memory-size 512))) @@ -209,7 +210,7 @@ (define* (run-jami-test #:key provisioning? partial?) (test-assert "service can be stopped" (marionette-eval '(begin - (use-modules (gnu build dbus-service) + (use-modules (gnu build utils) (gnu build jami-service) (gnu services herd) (rnrs base)) @@ -223,10 +224,10 @@ (define* (run-jami-test #:key provisioning? partial?) (test-assert "service can be restarted" (marionette-eval '(begin - (use-modules (gnu build dbus-service) + (use-modules (gnu build utils) (gnu build jami-service) (gnu services herd) - (rnrs base) ) + (rnrs base)) ;; Start the service. (start-service 'jami) (with-retries 40 1 (jami-service-available?)) @@ -239,7 +240,7 @@ (define* (run-jami-test #:key provisioning? partial?) (test-assert "jami accounts provisioning, account present" (marionette-eval '(begin - (use-modules (gnu build dbus-service) + (use-modules (gnu build utils) (gnu services herd) (rnrs base)) ;; Accounts take some time to appear after being added.