Skip to content

Commit

Permalink
added triton notification service, to test on qc
Browse files Browse the repository at this point in the history
  • Loading branch information
samouzegar10 committed Jul 26, 2024
1 parent 1149b75 commit 9ceffab
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 61 deletions.
33 changes: 33 additions & 0 deletions triton-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions triton-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"kysely": "^0.26.3",
"memorystore": "^1.6.7",
"node-cron": "^3.0.3",
"nodemailer": "^6.9.14",
"pino": "^8.14.1",
"serve-favicon": "^2.5.0",
"sqlite3": "^5.1.7"
Expand All @@ -64,6 +65,7 @@
"@types/express-session": "^1.17.5",
"@types/node": "^18.7.11",
"@types/node-cron": "^3.0.11",
"@types/nodemailer": "^6.4.15",
"@types/serve-favicon": "^2.5.3",
"@types/sqlite3": "^3.1.8",
"globals": "^15.6.0",
Expand Down
27 changes: 14 additions & 13 deletions triton-server/src/api/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
} from "./api-types"

export async function listRunsByExternalProjectId(
externalProjectIds: string[],
externalProjectIds: string[]
): Promise<TritonRun[]> {
const freezemanApi = await getFreezeManAuthenticatedAPI()
const datasetsResponse =
await freezemanApi.Dataset.listByExternalProjectIds(externalProjectIds)
const datasets = datasetsResponse.data.results.filter(
(dataset) => dataset.released_status_count > 0,
(dataset) => dataset.released_status_count > 0
)
const datasetsByRunIDAndProjectID = datasets.reduce<{
[projectID: string]: { [runName: string]: typeof datasets }
Expand All @@ -41,11 +41,11 @@ export async function listRunsByExternalProjectId(
datasets: datasets.map((d) => d.id),
readsetCount: datasets.reduce(
(total, d) => total + d.readset_count,
0,
0
),
availableReadsetsCount: datasets.reduce(
(total, d) => total + d.released_status_count,
0,
0
),
})
}
Expand All @@ -55,7 +55,7 @@ export async function listRunsByExternalProjectId(
}

export async function listDatasetsByIds(
datasetIds: string[],
datasetIds: string[]
): Promise<TritonDataset[]> {
const freezemanApi = await getFreezeManAuthenticatedAPI()
const datasetsResponse = await freezemanApi.Dataset.list(datasetIds)
Expand All @@ -64,15 +64,15 @@ export async function listDatasetsByIds(
}

export async function listRequests(
datasetIds: Array<TritonDataset["id"]>,
datasetIds: Array<TritonDataset["id"]>
): Promise<TritonRequest[]> {
const { listRequestByDatasetId } = await defaultDatabaseActions()
return (
await Promise.all(
datasetIds.map(
async (datasetId) =>
await listRequestByDatasetId(datasetId.toString()),
),
await listRequestByDatasetId(datasetId.toString())
)
)
).reduce<TritonRequest[]>((requests, request) => {
if (request) {
Expand All @@ -83,17 +83,18 @@ export async function listRequests(
}

export async function listReadsetsByDataset(
datasetId: TritonDataset["id"],
datasetId: TritonDataset["id"]
): Promise<TritonReadset[]> {
const freezemanApi = await getFreezeManAuthenticatedAPI()
const readsetsResponse =
await freezemanApi.Readset.listByDatasetId(datasetId)
const readsetsResponse = await freezemanApi.Readset.listByDatasetId(
datasetId
)
const readsets = [...readsetsResponse.data.results] // it's a readonly array
return readsets
}

export async function listDatasetFilesByDataset(
datasetId: TritonDataset["id"],
datasetId: TritonDataset["id"]
): Promise<TritonDatasetFile[]> {
const freezemanApi = await getFreezeManAuthenticatedAPI()
const readsets = (
Expand Down Expand Up @@ -134,6 +135,6 @@ export async function listDatasetFilesByDataset(
}
return tritonDatasetFiles
},
[],
[]
)
}
2 changes: 1 addition & 1 deletion triton-server/src/api/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TritonProject } from "./api-types"
*/
export async function listUserProjects(
userId: string,
userToken: string,
userToken: string
): Promise<TritonProject[]> {
const magicProjects = await getUserProjects(userId, userToken)

Expand Down
36 changes: 18 additions & 18 deletions triton-server/src/contact-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export function start() {
async (send) => {
await send(
getCredentialSubjectFor(contact),
getCredentialMessageFor(contact),
getCredentialMessageFor(contact)
)
},
}
)

logger.info(`[contacts] Removing contact ${contact.id}`)
Expand All @@ -49,19 +49,19 @@ export function start() {
.catch((error) =>
logger.error(
error,
`[contacts] Could not remove contact ${contact.id}`,
),
`[contacts] Could not remove contact ${contact.id}`
)
)
}
}),
})
)

const requests = await db.listRequests()
logger.debug(`[contacts] Found ${requests.length} requests`)
await Promise.allSettled(
requests.map(async (request) => {
logger.debug(
`[contacts] Processing request: ${JSON.stringify(request)}`,
`[contacts] Processing request: ${JSON.stringify(request)}`
)
const completionDate =
request.completion_date && new Date(request.completion_date)
Expand All @@ -83,9 +83,9 @@ export function start() {
await send(
`${subject}`,
`${subject}.<br/>
The dataset can be downloaded using ${request.type} using the credential provided to you.`,
The dataset can be downloaded using ${request.type} using the credential provided to you.`
)
},
}
)
await db.updateNotificationDate(request.id)
}
Expand All @@ -99,11 +99,11 @@ export function start() {
request.project_id,
async (send) => {
await send(`${subject}`, `${subject}.`)
},
}
)
await db.updateNotificationDate(request.id)
}
}),
})
)
}

Expand All @@ -113,8 +113,8 @@ export function start() {
export async function broadcastEmailsOfProject(
projectID: string,
fn: (
sendEmail: (subject: string, message: string) => Promise<void>,
) => Promise<void>,
sendEmail: (subject: string, message: string) => Promise<void>
) => Promise<void>
) {
const emails = await getEmailsForProject(projectID)

Expand All @@ -124,9 +124,9 @@ export async function broadcastEmailsOfProject(
logger.info(`[contacts] Sending email to ${to}`)
await sendEmail("", to, subject, message)
}).catch((error) =>
logger.error(error, `[contacts] Could not send email to ${to}`),
logger.error(error, `[contacts] Could not send email to ${to}`)
)
}),
})
)
}

Expand Down Expand Up @@ -205,7 +205,7 @@ function getCredentialMessageFor(contact: Contact) {
}

async function getEmailsForProject(
projectID: ExternalProjectID,
projectID: ExternalProjectID
): Promise<string[]> {
try {
const { users } = await getProjectUsers(projectID)
Expand All @@ -221,12 +221,12 @@ async function getEmailsForProject(
"",
config.mail.errorMonitoring,
subject,
`ProjectID: ${projectID}<br/><pre>${stack}</pre>`,
`ProjectID: ${projectID}<br/><pre>${stack}</pre>`
).catch((error) =>
logger.error(
error,
`[contacts] Could not send email to ${config.mail.errorMonitoring}`,
),
`[contacts] Could not send email to ${config.mail.errorMonitoring}`
)
)
}

Expand Down
Loading

0 comments on commit 9ceffab

Please sign in to comment.