Prettiering

This commit is contained in:
Collin Duncan 2023-01-20 09:52:28 +01:00
parent dfcb1f25a1
commit a18a9ca34d
No known key found for this signature in database
4 changed files with 75 additions and 59 deletions

View file

@ -42,7 +42,9 @@ export const hashPassword = async (password: string) => {
const hash = await generateHash(password, saltBuffer) const hash = await generateHash(password, saltBuffer)
return hash return hash
} catch (err: any) { } catch (err: any) {
asyncLocalStorage.getStore()?.error('Error hashing and salting password', { message: err.message }) asyncLocalStorage
.getStore()
?.error('Error hashing and salting password', { message: err.message })
throw err throw err
} }
} }

View file

@ -54,7 +54,9 @@ export class Runner {
reservation.booked = true reservation.booked = true
return true return true
} catch (err) { } catch (err) {
asyncLocalStorage.getStore()?.error('Error making reservation', reservation.format()) asyncLocalStorage
.getStore()
?.error('Error making reservation', reservation.format())
return false return false
} }
} }
@ -77,7 +79,9 @@ export class Runner {
asyncLocalStorage.getStore()?.debug(`Navigating to ${date.format()}`) asyncLocalStorage.getStore()?.debug(`Navigating to ${date.format()}`)
if (this.getLastVisibleDay().isBefore(date)) { if (this.getLastVisibleDay().isBefore(date)) {
asyncLocalStorage.getStore()?.debug('Date is on different page, increase month') asyncLocalStorage
.getStore()
?.debug('Date is on different page, increase month')
await this.page?.waitForSelector('td.month.next').then((d) => d?.click()) await this.page?.waitForSelector('td.month.next').then((d) => d?.click())
} }
@ -96,7 +100,9 @@ export class Runner {
} }
private async selectAvailableTime(res: Reservation): Promise<void> { private async selectAvailableTime(res: Reservation): Promise<void> {
asyncLocalStorage.getStore()?.debug('Selecting available time', res.format()) asyncLocalStorage
.getStore()
?.debug('Selecting available time', res.format())
let freeCourt: ElementHandle | null | undefined let freeCourt: ElementHandle | null | undefined
let i = 0 let i = 0
while (i < res.possibleDates.length && !freeCourt) { while (i < res.possibleDates.length && !freeCourt) {

View file

@ -18,16 +18,21 @@ export const startTasks = () => {
const task = schedule( const task = schedule(
'0 * * * * *', '0 * * * * *',
async (timestamp) => { async (timestamp) => {
asyncLocalStorage.run(new Logger('cron', v4(), LogLevel.DEBUG), async () => { asyncLocalStorage.run(
new Logger('cron', v4(), LogLevel.DEBUG),
async () => {
const childLogger = asyncLocalStorage.getStore() const childLogger = asyncLocalStorage.getStore()
childLogger?.info('Running cron job', { timestamp }) childLogger?.info('Running cron job', { timestamp })
try { try {
await reserve() await reserve()
childLogger?.info('Completed running cron job') childLogger?.info('Completed running cron job')
} catch (error: any) { } catch (error: any) {
childLogger?.error('Error running cron job', { error: error.message }) childLogger?.error('Error running cron job', {
} error: error.message,
}) })
}
}
)
}, },
getTaskConfig('reserver cron') getTaskConfig('reserver cron')
) )

View file

@ -6,7 +6,9 @@ import { parseJson } from './utils'
// Handles POST requests to /reservations // Handles POST requests to /reservations
const server = http.createServer(async (req, res) => { const server = http.createServer(async (req, res) => {
await asyncLocalStorage.run(new Logger('request', v4(), LogLevel.DEBUG), async () => { await asyncLocalStorage.run(
new Logger('request', v4(), LogLevel.DEBUG),
async () => {
const logger = asyncLocalStorage.getStore() const logger = asyncLocalStorage.getStore()
logger?.debug('Incoming request') logger?.debug('Incoming request')
const { url, method } = req const { url, method } = req
@ -53,7 +55,8 @@ const server = http.createServer(async (req, res) => {
} }
res.end() res.end()
}) }
)
}) })
export default server export default server