Skip to content

Commit 8b367be

Browse files
authored
Merge pull request #1237 from ctti-clinicaltrials/dev
Release
2 parents adb7a75 + 887c109 commit 8b367be

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you need a copy of the database, but don't want to bother installing & runnin
99
Below you'll find an image that illustrates the different AACT databases and schemas, while briefly describing their purposes.
1010
![Visualization of the database arrangment for AACT(backend) and AACT-Admin(frontend)](public/aact_architecture.png "AACT Database Visualization")
1111

12-
## Requireqments
12+
## Requirements
1313

1414
- Install zip
1515
- For mac `brew install zip`
@@ -29,10 +29,11 @@ Common for Core and Admin apps setting up problems/issues:
2929
1. Ubuntu versions 22.04 and newer have no built-in openssl 1.1.1 and it causes problems with the installation of ruby versions older than 3.02 (information actual 6/20/2023).
3030
2. Keep in mind that these 2 apps will interact with each other, the purpose of the Core app is for populating DB only. AACT-admin uses the same db as AACT-core. Do not try to "rails s" AACT-core.
3131
3. In those 2 lines in the environment variables file:
32-
`export AACT_CORE_DATABASE_URL=postgres://username:passw@localhost:5432/aact`
33-
`export AACT_CORE_TEST_DATABASE_URL=postgres://username:passw@localhost:5432/aact_test`
32+
`export AACT_CORE_DATABASE_URL=postgres://username:password@localhost:5432/aact`
33+
`export AACT_CORE_TEST_DATABASE_URL=postgres://username:password@localhost:5432/aact_test`
34+
3435
username - your Postgresql DB username
35-
passw - your postgres DB password
36+
password - your postgres DB password
3637

3738
## Getting Started
3839

@@ -89,15 +90,15 @@ passw - your postgres DB password
8990
```bash
9091
export AACT_PASSWORD=54104754
9192
export AACT_USERNAME=user_name
92-
export PGPASSWORD=passw
93+
export PGPASSWORD=password
9394
export TEST_PUBLIC_DB_USER=user_name
94-
export TEST_PUBLIC_DB_PASS=passw
95+
export TEST_PUBLIC_DB_PASS=password
9596
export PUBLIC_DB_USER=user_name
96-
export PUBLIC_DB_PASS=passw
97+
export PUBLIC_DB_PASS=password
9798
export AACT_DB_SUPER_USERNAME=user_name
9899
export PATH=$PATH:/lib/postgresql/15/bin
99-
export AACT_CORE_DATABASE_URL=postgres://DB_USER_NAME:DB_PASSW@localhost:5432/aact
100-
export AACT_CORE_TEST_DATABASE_URL=postgres://DB_USER_NAME:DB_PASSW@localhost:5432/aact_test
100+
export AACT_CORE_DATABASE_URL=postgres://DB_USER_NAME:DB_PASSWORD@localhost:5432/aact
101+
export AACT_CORE_TEST_DATABASE_URL=postgres://DB_USER_NAME:DB_PASSWORD@localhost:5432/aact_test
101102
```
102103

103104
Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
@@ -127,7 +128,7 @@ export DIGITALOCEAN_BUCKET=aact-dev
127128
Example: `export PATH=$PATH:/Library/PostgreSQL/13/bin`
128129
https://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac/
129130

130-
9. In the database.yml file, which is in config folder, lines 1-32 should look like:
131+
9. In the database.yml file, which is in config folder, lines 1-33 should look like:
131132

132133
```
133134
default: &default
@@ -185,11 +186,11 @@ development:
185186
The seed files are out of date so **DO NOT** call `db:seed`. Instead use the custom rake tasks.
186187
These are your options:
187188
* `bin/rake db:restore_from_file[<path_to_file>,<database_name>]`
188-
For this option go to https://aact.ctti-clinicaltrials.org/snapshots and download a copy of the database. Unzip the snapshot folder.
189-
The file path will likely look like: `~/Downloads/<unzipped_snapshot_folder>/postgres_data.dmp`
190-
Example: `~/Downloads/20210906_clinical_trials/postgres_data.dmp`.
191-
Give this task the path to the postgres_data.dmp file and it will use it to populate the database.
192-
Example: `bin/rake "db:restore_from_file[~/Downloads/20210906_clinical_trials/postgres_data.dmp,aact]"`
189+
For this option go to https://aact.ctti-clinicaltrials.org/snapshots and download a copy of the database. Unzip the snapshot folder and rename it to match the date of the snapshot it contains in a YYYYMMDD format (ex: 20250314_clinical_trials_ctgov).
190+
The file path will likely look like: `~/Downloads/<unzipped_snapshot_folder>/postgres.dmp`
191+
Example: `~/Downloads/20250314_clinical_trials_ctgov/postgres.dmp`.
192+
Give this task the path to the postgres.dmp file and it will use it to populate the database.
193+
Example: `bin/rake "db:restore_from_file[~/Downloads/20250314_clinical_trials_ctgov/postgres.dmp,aact]"`
193194
* `bin/rake db:restore_from_url[<url>,<database_name>]`
194195
For this option go to https://aact.ctti-clinicaltrials.org/snapshots and copy the link for one of the database copies. Give this task the url you copied and it will download the file, unzip it, and use it to populate the database.
195196
*Note: the rake tasks below take a very long time to run. You should not set full_featured to true if working locally.*

app/models/util/db_manager.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,32 @@ def initialize(params={})
1919
##### connection management #####
2020

2121
def public_connection
22-
connection = PublicBase.connection
23-
connection.schema_search_path = @schema
24-
# puts "public connection: #{connection.schema_search_path}"
25-
connection
22+
max_attempts = 3
23+
attempt = 0
24+
backoff_time = 20
25+
26+
begin
27+
attempt += 1
28+
connection = PublicBase.connection
29+
connection.schema_search_path = @schema
30+
connection.execute("SELECT 1")
31+
return connection
32+
rescue PG::ConnectionBad, ActiveRecord::StatementInvalid => e
33+
if attempt < max_attempts
34+
log("Public database connection error: #{e.message}. Retrying in #{backoff_time}s (#{attempt}/#{max_attempts})")
35+
36+
PublicBase.connection_pool.disconnect! # Force reconnection
37+
sleep(backoff_time)
38+
39+
backoff_time *= 2 # Exponential backoff
40+
retry
41+
else
42+
msg = "Failed to establish public database connection after #{max_attempts} attempts: #{e.message}"
43+
log(msg)
44+
event&.add_problem("#{Time.zone.now}: #{msg}")
45+
raise e
46+
end
47+
end
2648
end
2749

2850
def staging_connection
@@ -171,6 +193,10 @@ def restore_from_url(params = {})
171193
# 2. if successful restore to public db
172194
def refresh_public_db
173195
restore_database(public_connection, fm.pg_dump_file)
196+
rescue => e
197+
error_msg = "Failed to refresh public database: #{e.message}"
198+
log(error_msg)
199+
event&.add_problem("#{Time.zone.now}: #{error_msg}")
174200
end
175201

176202
def run_command_line(cmd)

app/models/util/updater_v2.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ def worker
6565
end
6666

6767
def db_mgr
68-
# makes it "singleton-like" inside the class
69-
@db_mgr ||= Util::DbManager.new(event: @load_event, schema: @schema)
68+
if @db_mgr.nil?
69+
@db_mgr = Util::DbManager.new(event: @load_event, schema: @schema)
70+
else
71+
@db_mgr.event = @load_event # always has acccess to the latest event
72+
end
73+
return @db_mgr
7074
end
7175

7276
def update_current_studies

0 commit comments

Comments
 (0)