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

Commit

Permalink
fix: set root for scheduler cron span
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Jul 11, 2022
1 parent b57212b commit ca9598f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
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
39 changes: 18 additions & 21 deletions dealer/src/app/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ import cron from "node-cron"

import { baseLogger } from "../services/logger"
import { Dealer } from "../Dealer"
import { recordExceptionInCurrentSpan, wrapAsyncToRunInSpan } from "../services/tracing"
import { ErrorLevel } from "../Result"
import { wrapAsyncToRunInSpan } from "../services/tracing"

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) {
baseLogger.warn({error}, "Error in Scheduler job")
}
},
}))
}

0 comments on commit ca9598f

Please sign in to comment.