aboutsummaryrefslogtreecommitdiff
path: root/genenetwork
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-07-03 17:55:07 -0500
committerFrederick Muriuki Muriithi2024-07-12 11:29:00 -0500
commit6e54a8444097f14ea905584fcc51d40ed22ef5d7 (patch)
treecb3b54fa2f4297606bc9c03fe02b721ba5846ee3 /genenetwork
parent9bde226e0219f6b41e8840e569b6fe0b09311df9 (diff)
downloadgn-machines-6e54a8444097f14ea905584fcc51d40ed22ef5d7.tar.gz
Generalise index-genenetwork cron gexp
Pass in the configuration to the gexp building function to make the builder function work across environments.
Diffstat (limited to 'genenetwork')
-rw-r--r--genenetwork/services/genenetwork.scm78
1 files changed, 77 insertions, 1 deletions
diff --git a/genenetwork/services/genenetwork.scm b/genenetwork/services/genenetwork.scm
index 48dfcc8..6c08703 100644
--- a/genenetwork/services/genenetwork.scm
+++ b/genenetwork/services/genenetwork.scm
@@ -22,10 +22,11 @@
(define-module (genenetwork services genenetwork)
#:use-module ((gn packages genenetwork) #:select (genenetwork2 genenetwork3 gn-auth gn-uploader))
#:use-module ((gnu packages web) #:select (nginx))
- #:use-module ((gnu packages admin) #:select (shadow))
+ #:use-module ((gnu packages admin) #:select (shadow shepherd))
#:use-module ((gnu packages python) #:select (python))
#:use-module (gnu services)
#:use-module (gnu services web)
+ #:use-module (gnu services mcron)
#:use-module (gnu system file-systems)
#:use-module (gnu system shadow)
#:use-module (guix build python-build-system)
@@ -132,6 +133,81 @@
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin")))))
+(define (build-xapian-index-cron-gexp config)
+ (let* ((sql-uri (genenetwork-configuration-sql-uri config))
+ (genenetwork3 (genenetwork-configuration-genenetwork3 config))
+ (xapian-directory (genenetwork-configuration-xapian-db config))
+ (sparql-endpoint (genenetwork-configuration-sparql-endpoint config))
+ (xapian-build-directory (string-append xapian-directory "/build"))
+ (herd (file-append shepherd "/bin/herd"))
+ (index-genenetwork (file-append genenetwork3 "/bin/index-genenetwork"))
+ (gn3-profile (profile
+ (content (package->development-manifest genenetwork3))
+ (allow-collisions? #t)))
+ (python3-version (python-version (package-version python))))
+ (with-imported-modules '((guix build utils))
+ #~(begin
+ (use-modules (guix build utils)
+ (srfi srfi-26))
+
+ ;; Use GN3 in container, not newly cloned GN3 to avoid
+ ;; inconsistencies between versions
+ (setenv "PYTHONPATH"
+ (string-append #$(file-append genenetwork3
+ "/lib/python"
+ python3-version
+ "/site-packages")
+ ":"
+ #$gn3-profile
+ "/lib/python"
+ #$python3-version
+ "/site-packages"))
+
+ (when (and
+ ;; not currently building an index
+ (not (file-exists? #$xapian-build-directory))
+ ;; data has been modified
+ (zero? (status:exit-val (system* #$index-genenetwork
+ "is-data-modified"
+ #$xapian-directory
+ #$sql-uri
+ #$sparql-endpoint))))
+ (dynamic-wind
+ (const #t)
+ ;; build the index
+ (lambda ()
+ (invoke #$index-genenetwork
+ "create-xapian-index"
+ #$xapian-build-directory
+ #$sql-uri
+ #$sparql-endpoint)
+ (dynamic-wind
+ ;; stop GN3: Here there is magic!!!
+ ;; The name `gunicorn-genenetwork' is magical. It is not set
+ ;; here nor at the point of call, rather, it is set in a
+ ;; dependency of the system (forge), thereby creating a
+ ;; coupling between this g-expression and whatever forge
+ ;; is doing. We need to figure out a way to pass in the
+ ;; service name as part of the call to break that coupling
+ (cut invoke #$herd "stop" "gunicorn-genenetwork3")
+ ;;replace old index
+ (lambda ()
+ (for-each (lambda (file)
+ (rename-file file
+ (string-append #$xapian-directory
+ "/"
+ (basename file))))
+ (find-files #$xapian-build-directory)))
+ ;; restart GN3
+ (cut invoke #$herd "start" "gunicorn-genenetwork3")))
+ (lambda ()
+ ;; delete build directory
+ (delete-file-recursively #$xapian-build-directory)
+ ;; set up correct permissions
+ (for-each (lambda (file)
+ (chmod file #o644))
+ (find-files #$xapian-directory)))))))))
+
(define (genenetwork-activation config)
(match-record config <genenetwork-configuration>
(gn2-secrets gn3-secrets gn-auth-secrets auth-db)