diff options
author | Christopher Baines <mail@cbaines.net> | 2021-02-03 10:35:56 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-02-03 10:35:56 +0000 |
commit | 643753ff463694f0e894526e46460fecc6c5b696 (patch) | |
tree | c3eb9932dad6b630c34510deca551870ac9b08ba /guix-data-service/jobs/load-new-guix-revision.scm | |
parent | 7fbcb3a3c26906ee130bcc64e88ea7a2b390de2c (diff) | |
download | data-service-643753ff463694f0e894526e46460fecc6c5b696.tar data-service-643753ff463694f0e894526e46460fecc6c5b696.tar.gz |
Better handle retries for jobs
This was broken when the guix_revisions entry started being added before the
final commit.
Diffstat (limited to 'guix-data-service/jobs/load-new-guix-revision.scm')
-rw-r--r-- | guix-data-service/jobs/load-new-guix-revision.scm | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm index 423043b..0e051f4 100644 --- a/guix-data-service/jobs/load-new-guix-revision.scm +++ b/guix-data-service/jobs/load-new-guix-revision.scm @@ -1316,20 +1316,32 @@ WHERE job_id = $1" store channel-for-commit fetch-with-authentication?))) - (let ((guix-revision-id - (insert-guix-revision conn git-repository-id commit))) - (insert-channel-instances conn - guix-revision-id - (filter-map - (match-lambda - ((system . derivations) - (and=> - (assoc-ref derivations - 'manifest-entry-item) - (lambda (drv) - (cons system drv))))) - channel-derivations-by-system)) + (with-time-logging + "acquiring advisory transaction lock: load-new-guix-revision-inserts" + ;; Wait until this is the only transaction inserting data, to avoid any + ;; concurrency issues + (obtain-advisory-transaction-lock conn + 'load-new-guix-revision-inserts)) + (let* ((existing-guix-revision-id + (git-repository-id-and-commit->revision-id conn + git-repository-id + commit)) + (guix-revision-id + (or existing-guix-revision-id + (insert-guix-revision conn git-repository-id commit)))) + (unless existing-guix-revision-id + (insert-channel-instances conn + guix-revision-id + (filter-map + (match-lambda + ((system . derivations) + (and=> + (assoc-ref derivations + 'manifest-entry-item) + (lambda (drv) + (cons system drv))))) + channel-derivations-by-system))) (simple-format (current-error-port) "guix-data-service: saving the channel instance derivations to the database\n") @@ -1777,32 +1789,30 @@ SKIP LOCKED") (simple-format #t "Processing job ~A (commit: ~A, source: ~A)\n\n" id commit source) - (if (or - (guix-revision-exists? conn git-repository-id commit) - (eq? - (with-time-logging (string-append "loading revision " commit) - (setup-logging - id - (lambda () - (with-exception-handler - (const #f) - (lambda () - (with-exception-handler - (lambda (exn) - (simple-format (current-error-port) - "error: load-new-guix-revision: ~A\n" - exn) - (backtrace) - #f) - (lambda () - (with-store-connection - (lambda (store) - (load-new-guix-revision conn - store - git-repository-id - commit)))))) - #:unwind? #t)))) - #t)) + (if (eq? + (with-time-logging (string-append "loading revision " commit) + (setup-logging + id + (lambda () + (with-exception-handler + (const #f) + (lambda () + (with-exception-handler + (lambda (exn) + (simple-format (current-error-port) + "error: load-new-guix-revision: ~A\n" + exn) + (backtrace) + #f) + (lambda () + (with-store-connection + (lambda (store) + (load-new-guix-revision conn + store + git-repository-id + commit)))))) + #:unwind? #t)))) + #t) (begin (record-job-succeeded conn id) (record-job-event conn id "success") |