Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ikprk committed May 29, 2024
1 parent c10dc78 commit 2178c1e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/mail-scheduler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConfigVariable, config } from '../utils/config'
import { uniqueId } from '../utils/crypto'
import { globalEm } from '../utils/globalEm'
import { createMailContent, executeMailDelivery } from './utils'
import { updateJoystreamPrice } from '../utils/joystreamPrice'

export async function getMaxAttempts(em: EntityManager): Promise<number> {
const maxAttempts = await config.get(ConfigVariable.EmailNotificationDeliveryMaxAttempts, em)
Expand All @@ -31,6 +32,7 @@ export async function mailsToDeliver(em: EntityManager): Promise<NotificationEma

export async function deliverEmails() {
const em = await globalEm
await updateJoystreamPrice()
const newEmailDeliveries = await mailsToDeliver(em)
const maxAttempts = await getMaxAttempts(em)
const appName = await config.get(ConfigVariable.AppName, em)
Expand Down
2 changes: 1 addition & 1 deletion src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ processor.run(new TypeormDatabase({ isolationLevel: 'READ COMMITTED' }), async (
await updateJoystreamPrice()
schedulePriceUpdate()
.then(() => undefined)
.catch(() => ctx.log.error('Fetching JOYSTREAM price failed'))
.catch(() => undefined)
}

const overlay = await EntityManagerOverlay.create(ctx.store, afterDbUpdate)
Expand Down
11 changes: 8 additions & 3 deletions src/utils/joystreamPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ const MAX_SAFE_NUMBER_BN = new BN(Number.MAX_SAFE_INTEGER)
const log = createLogger('price')

export const updateJoystreamPrice = async () => {
const data = await fetch('https://status.joystream.org/price')
const json = await data.json()
JOYSTREAM_USD_PRICE = +json.price ?? 0
// we don't care if the request fails, app should continue to work w/o joy price
const data = await fetch('https://status.joystream.org/price').catch(() =>
log.error('Fetching JOYSTREAM price failed')
)
if (data) {
const json = await data.json()
JOYSTREAM_USD_PRICE = +json.price ?? 0
}
}

export const schedulePriceUpdate = async (): Promise<void> => {
Expand Down

0 comments on commit 2178c1e

Please sign in to comment.