Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rc-code/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use the SafeInsights R 4.5.1 base image
FROM harbor.safeinsights.org/safeinsights-public/base-container:r4.5.1-2025-09-19-15-47-18

RUN apt-get update && apt-get install -y \
nano \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /code

COPY longRC.r ./code/longRC.r

CMD ["Rscript", "./code/longRC.r"]
12 changes: 12 additions & 0 deletions rc-code/build-n-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

TAG="${1:-$(date +"%Y-%m-%d-%H-%M-%S")}"

docker buildx build \
--file Dockerfile \
--platform=linux/amd64 \
--progress=plain \
-t harbor.safeinsights.org/openstax/code-builds/dev:$TAG \
.

docker push harbor.safeinsights.org/openstax/code-builds/dev:$TAG
5 changes: 5 additions & 0 deletions rc-code/longRC.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print("Welcome to the script.")
time <- 3600
print(paste0("Waiting ", time / 60, " minutes ..."))
Sys.sleep(time)
print(paste0(time / 60, " minutes have passed. Script over."))
2 changes: 1 addition & 1 deletion src/lib/aws-run-studies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { managementAppGetReadyStudiesRequest, toaGetJobsRequest, toaUpdateJobSta
import 'dotenv/config'
import { ManagementAppGetReadyStudiesResponse } from './types'

async function launchStudy(
export async function launchStudy(
client: ECSClient,
cluster: string,
baseTaskDefinitionFamily: string,
Expand Down
1 change: 1 addition & 0 deletions src/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export async function runECSFargateTask(
},
},
tags: tags,
enableExecuteCommand: true,
}
const command = new RunTaskCommand(jobTaskInput)
console.log('AWS: START: Prompting an ECS task to run ...')
Expand Down
12 changes: 4 additions & 8 deletions src/scripts/poll.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { checkForErroredJobs } from '../lib/check-jobs'
import { runStudies } from '../lib/run-studies'

const pollStudiesInterval = parseInt(process.env.POLL_STUDIES_INTERVAL_SECONDS ?? '30')
const pollForErroredJobsInterval = parseInt(process.env.POLL_ERRORED_JOBS_INTERVAL_SECONDS ?? '60')

console.log('Polling interval for studies:', pollStudiesInterval)
console.log('Polling interval for failed jobs:', pollForErroredJobsInterval)
function pollStudies(): void {
console.log(`Polling management app at ${new Date()}`)

runStudies({ ignoreAWSJobs: false })
// console.log(`Polling management app at ${new Date()}`)
// runStudies({ ignoreAWSJobs: false })
}

function pollForErroredJobs(): void {
console.log(`Polling for errored jobs at ${new Date()}`)
checkForErroredJobs()
// console.log(`Polling for errored jobs at ${new Date()}`)
// checkForErroredJobs()
}

// Poll for studies every 10 minutes by default (for dev)
Expand Down
32 changes: 32 additions & 0 deletions src/scripts/start-long-rc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { launchStudy } from '../lib/aws-run-studies'
import { ensureValueWithError } from '../lib/utils'
import { ECSClient } from '@aws-sdk/client-ecs'

const main = async (): Promise<void> => {
const ecsClient = new ECSClient()

// Get vals from env vars set in IaC
const cluster = ensureValueWithError(process.env.ECS_CLUSTER, 'Env var ECS_CLUSTER not found')
const baseTaskDefinition = ensureValueWithError(
process.env.BASE_TASK_DEFINITION_FAMILY,
'Env var BASE_TASK_DEFINITION_FAMILY not found',
)
const subnets = ensureValueWithError(process.env.VPC_SUBNETS, 'Env var VPC_SUBNETS not found')
const securityGroup = ensureValueWithError(process.env.SECURITY_GROUP, 'Env var SECURITY_GROUP not found')

// Launch the study
await launchStudy(
ecsClient,
cluster,
baseTaskDefinition,
subnets.split(','),
securityGroup,
'N/A', // no need to supply correct TOA endpoint
'test-job-id',
// URL to container built from files in `../../rc-code/` directory:
'harbor.safeinsights.org/openstax/code-builds/dev:2025-10-17-16-31-40',
'Exec-able container',
)
}

main()
Loading