From b0c1c76152430950a704c5bc3d42dcfe11dfffa2 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 23 Jan 2025 00:27:27 +0000 Subject: slurm-api: Bind return value of slurm-http-get in the state monad. * ravanan/slurm-api.scm (job-state): Bind return value of slurm-http-get in the state monad. --- ravanan/slurm-api.scm | 53 ++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/ravanan/slurm-api.scm b/ravanan/slurm-api.scm index 7c479ee..32dc3c7 100644 --- a/ravanan/slurm-api.scm +++ b/ravanan/slurm-api.scm @@ -118,35 +118,36 @@ monad." jwt (string-append "/slurm/v0.0.41/job/" (number->string job-id))))) - (state-return - (match (json-ref response "errors") - (#() + (match (json-ref response "errors") + (#() + (state-return (match (json-ref (find (lambda (job) (= (json-ref job "job_id") job-id)) (vector->list (json-ref response "jobs"))) "job_state") (#(job-state) - (string->symbol (string-downcase job-state))))) - (#(errors ...) - ;; Check in slurmdbd if job has been completed and purged from - ;; slurmctld's active memory. - (match (find (lambda (error) - (= (json-ref error "error_number") - ;; Error number 2017 (Invalid job id specified) may - ;; have occurred because the job has completed, has - ;; exceeded MinJobAge (as set in slurm.conf) and has - ;; therefore been purged from slurmctld's active - ;; memory. - 2017)) - errors) - (error-2017 - (let ((response - (check-api-error - (slurm-http-get api-endpoint - jwt - (string-append "/slurmdb/v0.0.41/job/" - (number->string job-id)))))) + (string->symbol (string-downcase job-state)))))) + (#(errors ...) + ;; Check in slurmdbd if job has been completed and purged from + ;; slurmctld's active memory. + (match (find (lambda (error) + (= (json-ref error "error_number") + ;; Error number 2017 (Invalid job id specified) may + ;; have occurred because the job has completed, has + ;; exceeded MinJobAge (as set in slurm.conf) and has + ;; therefore been purged from slurmctld's active + ;; memory. + 2017)) + errors) + (error-2017 + (state-let* ((response + (slurm-http-get api-endpoint + jwt + (string-append "/slurmdb/v0.0.41/job/" + (number->string job-id))))) + (check-api-error response) + (state-return (match (json-ref (find (lambda (job) (= (json-ref job "job_id") job-id)) @@ -157,6 +158,6 @@ monad." (if (eq? (string->symbol (string-downcase job-state)) 'success) 'success - 'failed))))) - (#f - (check-api-error response)))))))) + 'failed)))))) + (#f + (state-return (check-api-error response)))))))) -- cgit v1.2.3