Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

fix: set root for scheduler cron span #111

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dealer/src/app/dealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const main = async () => {

const DealerUpdatePositionAndLeverageTask = () => dealer.updatePositionAndLeverage()
const wrappedTask = wrapAsyncToRunInSpan({
root: true,
namespace: "app.dealer",
fn: DealerUpdatePositionAndLeverageTask,
})
Expand Down
40 changes: 21 additions & 19 deletions dealer/src/app/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import { ErrorLevel } from "../Result"
const logger = baseLogger.child({ module: "cron" })

export async function scheduler() {
cron.schedule("0,5,10,15,20,25,30,35,40,45,50,55 * * * *", async () => {
try {
const dealer = new Dealer(logger)
logger.info("Starting Dealer via Scheduler")
const DealerUpdatePositionAndLeverageTask = () => dealer.updatePositionAndLeverage()
const wrappedTask = wrapAsyncToRunInSpan({
namespace: "app.scheduler",
fn: DealerUpdatePositionAndLeverageTask,
})
const result = await wrappedTask()
baseLogger.info(
{ result },
`dealer.updatePositionAndLeverage() returned: ${result}`,
)
} catch (error) {
recordExceptionInCurrentSpan({ error, level: ErrorLevel.Warn })
baseLogger.warn(`Error in Scheduler job: ${error}`)
}
})
cron.schedule(
"0,5,10,15,20,25,30,35,40,45,50,55 * * * *",
wrapAsyncToRunInSpan({
root: true,
namespace: "app.scheduler",
fnName: "run",
fn: async () => {
try {
logger.info("Starting Dealer via Scheduler")

const dealer = new Dealer(logger)
const result = await dealer.updatePositionAndLeverage()

baseLogger.info({ result }, `Update position and leverage result`)
} catch (error) {
recordExceptionInCurrentSpan({ error, level: ErrorLevel.Warn })
baseLogger.warn({ error }, "Error in Scheduler job")
}
},
}),
)
}