Skip to content

Commit b0fbef3

Browse files
committed
dont send email after manual recalculation, sensible default noti preferences
1 parent 01a68fb commit b0fbef3

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/functions/src/functions/auth/login.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ export const login = async (req: HttpRequest, context: InvocationContext): Promi
2525
const emailRecord = new EmailRecipient()
2626
emailRecord.userId = user.szemely_id
2727
emailRecord.email = user.email
28-
// TODO only temporary
29-
emailRecord.eventImportedNotifications = EventImportedNotificationOptions.ALL
30-
emailRecord.resultNotifications = ResultNotificationOptions.ALL
28+
emailRecord.eventImportedNotifications = EventImportedNotificationOptions.ONLY_NATIONAL
29+
emailRecord.resultNotifications = ResultNotificationOptions.ONLY_RATED
3130
await emailRepo.save(emailRecord)
3231
} else if (userEmail.email !== user.email) {
3332
userEmail.email = user.email

packages/functions/src/functions/events/closeRating/closeRatingOrchestrator.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import { validateRatingsActivityName } from './validateRatingsActivity'
1111
export const orchestratorName = 'closeRatingOrchestrator'
1212
export type ActivityOutput = { eventId: number; success: boolean }
1313
export type CalculateRatingsActivityOutput = ActivityOutput & { actualResults: boolean }
14+
export type OrchestratorParams = {
15+
sendNotification: boolean
16+
events: { eventId: number; state: EventState }[]
17+
}
1418

1519
/**
1620
* Durable Functions orchestrator function that executes the activies that validate and accumulate the ratings of finished events.
@@ -29,12 +33,14 @@ export type CalculateRatingsActivityOutput = ActivityOutput & { actualResults: b
2933
* Called in parallel for all events whose ratings were successfully validated and events that are in the ACCUMULATING phase (because previous accumulation failed)
3034
* 4. SendNotifications
3135
* Activity to send notifications to subscribed users about the newly published rating results.
32-
* Only called if at least event has been closed with meaningful results (more than one rating). Called just once with the events that have meaningful results.
36+
* Only called if at least event has been closed with meaningful results (more than one rating),
37+
* the app is running in production mode and the orchestration was initiated by the close rating starter (called automatically at night), not the manual recalculate function.
38+
* Called just once with the events that have meaningful results.
3339
* 5. PublishOrchestrationResults
3440
* If the accumulation succeeded for at least one event, this activity is called once to save the Alert to the DB to notify the admins that the accumulation has finished.
3541
*/
3642
const orchestrator: OrchestrationHandler = function* (context: OrchestrationContext) {
37-
const events: { eventId: number; state: EventState }[] = context.df.getInput()
43+
const { events, sendNotification }: OrchestratorParams = context.df.getInput()
3844
context.log(`Orchestrator function started, starting the validation of ratings for ${events.length} event(s).`)
3945

4046
const eventsToRedo = events.filter((e) => e.state !== EventState.VALIDATING)
@@ -67,7 +73,7 @@ const orchestrator: OrchestrationHandler = function* (context: OrchestrationCont
6773
const accumulationSuccess = accumulationResults.filter((r) => r.success)
6874
if (accumulationSuccess.length > 0) {
6975
const eventsWithMeaningfulResults = accumulationSuccess.filter((r) => r.actualResults).map((r) => r.eventId)
70-
if (eventsWithMeaningfulResults.length > 0 && ENV === 'production') {
76+
if (eventsWithMeaningfulResults.length > 0 && ENV === 'production' && sendNotification) {
7177
yield context.df.callActivity(sendNotificationsActivityName, eventsWithMeaningfulResults)
7278
}
7379
yield context.df.callActivity(publishOrchestrationResultsActivityName, accumulationSuccess.length)

packages/functions/src/functions/events/closeRating/closeRatingStarter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const closeRatingStarter = async (myTimer: Timer, context: InvocationContext): P
3434
const toClose = [...toArchive, ...eventsWithoutResults.filter((e) => e.state !== EventState.RATEABLE)]
3535
if (toClose.length > 0) {
3636
const client = df.getClient(context)
37-
const instanceId = await client.startNew(orchestratorName, { input: toClose.map((e) => ({ eventId: e.id, state: e.state })) })
37+
const instanceId = await client.startNew(orchestratorName, {
38+
input: { sendNotification: true, events: toClose.map((e) => ({ eventId: e.id, state: e.state })) },
39+
})
3840
context.log(`Started orchestration with ID = '${instanceId}'.`)
3941
}
4042
} catch (error) {

packages/functions/src/functions/seasons/recalculate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const recalculateRatingsInSeason = async (req: HttpRequest, context: InvocationC
4242
await ads.getRepository(Event).save(invalidatedEvents)
4343
const client = df.getClient(context)
4444
const instanceId = await client.startNew(orchestratorName, {
45-
input: invalidatedEvents.map((e) => ({ eventId: e.id, state: e.state })),
45+
input: { sendNotification: false, events: invalidatedEvents.map((e) => ({ eventId: e.id, state: e.state })) },
4646
})
4747
context.log(`Started orchestration with ID = '${instanceId}'.`)
4848
} else {

0 commit comments

Comments
 (0)