Skip to content

Commit 040a8e4

Browse files
authored
✨ Curious data to REDCap (#17)
2 parents 049a355 + 19b93d7 commit 040a8e4

35 files changed

Lines changed: 3121 additions & 1692 deletions

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "javascript_jobs/autoexport"]
22
path = javascript_jobs/autoexport
3-
url = https://github.com/childmindresearch/mindlogger-autoexport.git
3+
url = git@github.com:childmindresearch/mindlogger-autoexport.git
44
branch = one-activity

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 1.5.0
9+
10+
### Added
11+
12+
- `mrn_error_log.tsv`
13+
- Python scripts / jobs
14+
- Curious data to REDCap
15+
- `{activity_name}_start_date` to Curious instruments in REDCap
16+
17+
### Fixed
18+
19+
- bug in pushing Curous alerts to REDCap
20+
- bug in pushing REDCap participants to Curious
21+
822
## 1.4.1
923

1024
### Added

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.5.0

infrastructure/main.tf

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ locals {
2727
service_prefix = terraform.workspace == "default" ? "" : "${terraform.workspace}-"
2828

2929
services = {
30-
ripple_sync = "${local.service_prefix}ripple-to-redcap"
31-
redcap_sync = "${local.service_prefix}redcap-to-redcap"
32-
redcap_to_curious = "${local.service_prefix}redcap-to-curious"
33-
curious_alerts_websocket = "${local.service_prefix}curious-alerts-websocket"
34-
hbn_sync_timer = "${local.service_prefix}hbn-sync.timer"
35-
hbn_sync_target = "${local.service_prefix}hbn-sync.target"
30+
ripple_sync = "${local.service_prefix}ripple-to-redcap"
31+
redcap_sync = "${local.service_prefix}redcap-to-redcap"
32+
redcap_to_curious = "${local.service_prefix}redcap-to-curious"
33+
curious_alerts_websocket = "${local.service_prefix}curious-alerts-websocket"
34+
curious_accounts_to_redcap = "${local.service_prefix}curious-accounts-to-redcap"
35+
curious_data_to_redcap = "${local.service_prefix}curious-data-to-redcap"
36+
hbn_sync_timer = "${local.service_prefix}hbn-sync.timer"
3637
}
3738
}
3839

@@ -138,26 +139,52 @@ resource "local_file" "curious_alerts_websocket_service" {
138139
depends_on = [null_resource.ensure_user_group]
139140
}
140141

141-
resource "local_file" "hbn_sync_timer" {
142-
content = templatefile("${path.module}/services/hbn-sync.timer.tpl", {
143-
sync_interval_minutes = var.sync_interval_minutes
144-
service_prefix = local.service_prefix
145-
workspace = terraform.workspace
142+
resource "local_file" "curious_accounts_to_redcap_service" {
143+
content = templatefile("${path.module}/services/curious-accouts-to-redcap.service.tpl", {
144+
user_group = var.user_group
145+
project_root = local.workspace_dir
146+
venv_path = local.venv_full_path
147+
log_directory = local.log_full_path
148+
workspace = terraform.workspace
146149
})
147-
filename = "${path.module}/.generated/${local.services.hbn_sync_timer}"
150+
filename = "${path.module}/.generated/${local.services.curious_accounts_to_redcap}.service"
148151
depends_on = [null_resource.ensure_user_group]
149152
}
150153

151-
resource "local_file" "hbn_sync_target" {
152-
content = templatefile("${path.module}/services/hbn-sync.target.tpl", {
153-
workspace = terraform.workspace
154+
resource "local_file" "curious_data_to_redcap_service" {
155+
content = templatefile("${path.module}/services/curious-data-to-redcap.service.tpl", {
156+
user_group = var.user_group
157+
project_root = local.workspace_dir
158+
venv_path = local.venv_full_path
159+
log_directory = local.log_full_path
160+
workspace = terraform.workspace
161+
})
162+
filename = "${path.module}/.generated/${local.services.curious_data_to_redcap}.service"
163+
depends_on = [null_resource.ensure_user_group]
164+
}
165+
166+
resource "local_file" "hbn_sync_service" {
167+
content = templatefile("${path.module}/services/hbn-sync.service.tpl", {
154168
services = [
155169
local.services.ripple_sync,
156170
local.services.redcap_sync,
157-
local.services.redcap_to_curious
171+
local.services.redcap_to_curious,
172+
local.services.curious_accounts_to_redcap,
173+
local.services.curious_alerts_websocket,
174+
local.services.curious_data_to_redcap
158175
]
159176
})
160-
filename = "${path.module}/.generated/${local.services.hbn_sync_target}"
177+
filename = "${path.module}/.generated/hbn-sync.service"
178+
depends_on = [null_resource.ensure_user_group]
179+
}
180+
181+
resource "local_file" "hbn_sync_timer" {
182+
content = templatefile("${path.module}/services/hbn-sync.timer.tpl", {
183+
sync_interval_minutes = var.sync_interval_minutes
184+
service_prefix = local.service_prefix
185+
workspace = terraform.workspace
186+
})
187+
filename = "${path.module}/.generated/${local.services.hbn_sync_timer}"
161188
depends_on = [null_resource.ensure_user_group]
162189
}
163190

@@ -192,15 +219,16 @@ resource "null_resource" "deploy_services" {
192219
local_file.redcap_sync_service.content,
193220
local_file.redcap_to_curious_service.content,
194221
local_file.curious_alerts_websocket_service.content,
222+
local_file.curious_accounts_to_redcap_service.content,
223+
local_file.curious_data_to_redcap_service.content,
224+
local_file.hbn_sync_service.content,
195225
local_file.hbn_sync_timer.content,
196-
local_file.hbn_sync_target.content,
197226
]))
198227
}
199228
provisioner "local-exec" {
200229
command = <<-EOT
201230
sudo cp ${path.module}/.generated/*.service /etc/systemd/system/
202231
sudo cp ${path.module}/.generated/*.timer /etc/systemd/system/
203-
sudo cp ${path.module}/.generated/*.target /etc/systemd/system/
204232
sudo systemctl daemon-reload
205233
echo "✓ Services deployed for workspace: ${terraform.workspace}"
206234
EOT
@@ -211,8 +239,10 @@ resource "null_resource" "deploy_services" {
211239
local_file.redcap_sync_service,
212240
local_file.redcap_to_curious_service,
213241
local_file.curious_alerts_websocket_service,
242+
local_file.curious_accounts_to_redcap_service,
243+
local_file.curious_data_to_redcap_service,
244+
local_file.hbn_sync_service,
214245
local_file.hbn_sync_timer,
215-
local_file.hbn_sync_target,
216246
]
217247
}
218248

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Unit]
2+
Description=Curious invitations to REDCap Sync Service [${workspace}]
3+
After=network.target
4+
5+
[Service]
6+
Type=oneshot
7+
User=${user_group}
8+
Group=${user_group}
9+
WorkingDirectory=${project_root}
10+
ExecStart=${venv_path}/bin/curious-invitations-to-redcap
11+
Environment="WORKSPACE=${workspace}"
12+
Environment="HBNMIGRATION_PROJECT_ROOT=${project_root}"
13+
Environment="HBNMIGRATION_LOG_PATH=${log_directory}"
14+
15+
# Logging
16+
BindPaths=/data/logs/hbnmigration:/home/hbnmigration/hbnmigration/.hbnmigration_logs
17+
StandardOutput=append:${log_directory}/curious-invitations-to-redcap.log
18+
StandardError=append:${log_directory}/curious-invitations-to-redcap.log
19+
SyslogIdentifier=curious-invitations-to-redcap-${workspace}
20+
21+
# Security hardening
22+
NoNewPrivileges=true
23+
PrivateTmp=true
24+
ProtectSystem=strict
25+
ReadWritePaths=${project_root}
26+
ReadWritePaths=${log_directory}
27+
28+
[Install]
29+
WantedBy=multi-user.target

infrastructure/services/curious-alerts-websocket.service.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ Group=${user_group}
99
WorkingDirectory=${project_root}
1010
ExecStart=${venv_path}/bin/curious-alerts-to-redcap --asynchronous
1111
Environment="WORKSPACE=${workspace}"
12+
Environment="HBNMIGRATION_PROJECT_ROOT=${project_root}"
13+
Environment="HBNMIGRATION_LOG_PATH=${log_directory}"
1214
Restart=always
1315
RestartSec=10
1416

1517
# Logging
18+
BindPaths=/data/logs/hbnmigration:/home/hbnmigration/hbnmigration/.hbnmigration_logs
1619
StandardOutput=append:${log_directory}/curious-alerts-websocket.log
1720
StandardError=append:${log_directory}/curious-alerts-websocket-error.log
1821
SyslogIdentifier=curious-alerts-websocket-${workspace}
@@ -21,7 +24,6 @@ SyslogIdentifier=curious-alerts-websocket-${workspace}
2124
NoNewPrivileges=true
2225
PrivateTmp=true
2326
ProtectSystem=strict
24-
ProtectHome=true
2527
ReadWritePaths=${project_root}
2628
ReadWritePaths=${log_directory}
2729

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Unit]
2+
Description=Curious data to REDCap Sync Service [${workspace}]
3+
After=network.target
4+
5+
[Service]
6+
Type=oneshot
7+
User=${user_group}
8+
Group=${user_group}
9+
WorkingDirectory=${project_root}
10+
ExecStart=${venv_path}/bin/curious-data-to-redcap
11+
Environment="WORKSPACE=${workspace}"
12+
Environment="HBNMIGRATION_PROJECT_ROOT=${project_root}"
13+
Environment="HBNMIGRATION_LOG_PATH=${log_directory}"
14+
15+
# Logging
16+
BindPaths=/data/logs/hbnmigration:/home/hbnmigration/hbnmigration/.hbnmigration_logs
17+
StandardOutput=append:${log_directory}/curious-data-to-redcap.log
18+
StandardError=append:${log_directory}/curious-data-to-redcap.log
19+
SyslogIdentifier=curious-data-to-redcap-${workspace}
20+
21+
# Security hardening
22+
NoNewPrivileges=true
23+
PrivateTmp=true
24+
ProtectSystem=strict
25+
ReadWritePaths=${project_root}
26+
ReadWritePaths=${log_directory}
27+
28+
[Install]
29+
WantedBy=multi-user.target
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=HBN Sync Service - Runs All Sync Services [default]
3+
After=network.target
4+
Wants=ripple-to-redcap.service redcap-to-redcap.service redcap-to-curious.service curious-accounts-to-redcap.service curious-alerts-websocket.service curious-data-to-redcap.service
5+
6+
[Service]
7+
Type=oneshot
8+
# This service just triggers the other services
9+
ExecStart=/bin/true
10+
BindPaths=/data/logs/hbnmigration:/home/hbnmigration/hbnmigration/.hbnmigration_logs
11+
12+
# The real work happens via dependencies
13+
ExecStartPost=/usr/bin/systemctl start ripple-to-redcap.service
14+
ExecStartPost=/usr/bin/systemctl start redcap-to-redcap.service
15+
ExecStartPost=/usr/bin/systemctl start redcap-to-curious.service
16+
ExecStartPost=/usr/bin/systemctl start curious-accounts-to-redcap.service
17+
ExecStartPost=/usr/bin/systemctl start curious-alerts-websocket.service
18+
ExecStartPost=/usr/bin/systemctl start curious-data-to-redcap.service
19+
20+
[Install]
21+
WantedBy=multi-user.target

infrastructure/services/hbn-sync.target.tpl

Lines changed: 0 additions & 6 deletions
This file was deleted.

infrastructure/services/hbn-sync.timer.tpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[Unit]
2-
Description=Ripple, REDCap and Curious Sync Timer [${workspace}]
3-
Requires=${service_prefix}ripple-to-redcap.service
4-
Requires=${service_prefix}redcap-to-redcap.service
5-
Requires=${service_prefix}redcap-to-curious.service
2+
Description=Ripple, REDCap and Curious Sync Timer [default]
3+
Requires=hbn-sync.service
64

75
[Timer]
8-
OnCalendar=*:0/${sync_interval_minutes}
6+
OnCalendar=*:0/1
97
Persistent=true
108

119
[Install]

0 commit comments

Comments
 (0)