Prettiering ✨
This commit is contained in:
parent
dfcb1f25a1
commit
a18a9ca34d
4 changed files with 75 additions and 59 deletions
|
|
@ -42,7 +42,9 @@ export const hashPassword = async (password: string) => {
|
|||
const hash = await generateHash(password, saltBuffer)
|
||||
return hash
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ export class Runner {
|
|||
reservation.booked = true
|
||||
return true
|
||||
} catch (err) {
|
||||
asyncLocalStorage.getStore()?.error('Error making reservation', reservation.format())
|
||||
asyncLocalStorage
|
||||
.getStore()
|
||||
?.error('Error making reservation', reservation.format())
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +79,9 @@ export class Runner {
|
|||
asyncLocalStorage.getStore()?.debug(`Navigating to ${date.format()}`)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +100,9 @@ export class Runner {
|
|||
}
|
||||
|
||||
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 i = 0
|
||||
while (i < res.possibleDates.length && !freeCourt) {
|
||||
|
|
|
|||
|
|
@ -18,16 +18,21 @@ export const startTasks = () => {
|
|||
const task = schedule(
|
||||
'0 * * * * *',
|
||||
async (timestamp) => {
|
||||
asyncLocalStorage.run(new Logger('cron', v4(), LogLevel.DEBUG), async () => {
|
||||
asyncLocalStorage.run(
|
||||
new Logger('cron', v4(), LogLevel.DEBUG),
|
||||
async () => {
|
||||
const childLogger = asyncLocalStorage.getStore()
|
||||
childLogger?.info('Running cron job', { timestamp })
|
||||
try {
|
||||
await reserve()
|
||||
childLogger?.info('Completed running cron job')
|
||||
} catch (error: any) {
|
||||
childLogger?.error('Error running cron job', { error: error.message })
|
||||
}
|
||||
childLogger?.error('Error running cron job', {
|
||||
error: error.message,
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
getTaskConfig('reserver cron')
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import { parseJson } from './utils'
|
|||
|
||||
// Handles POST requests to /reservations
|
||||
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()
|
||||
logger?.debug('Incoming request')
|
||||
const { url, method } = req
|
||||
|
|
@ -53,7 +55,8 @@ const server = http.createServer(async (req, res) => {
|
|||
}
|
||||
|
||||
res.end()
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
export default server
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue