Skip to content

Commit

Permalink
fix: job frequencies on solana weren't taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
amalcaraz committed Oct 21, 2024
1 parent 4ea71c6 commit 05da833
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 150 deletions.
89 changes: 9 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"graphql": "^16.9.0",
"husky": "^8.0.1",
"jest": "^28.1.0",
"lerna": "^7.1.4",
Expand Down
117 changes: 66 additions & 51 deletions packages/core/src/utils/concurrence/jobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface JobRunnerOptions {
jitter?: number
}

export type PartialJobRunnerOptions = Partial<JobRunnerOptions>

/**
* Runs an `intervalFn` at a given `interval`. The `intervalFn` can return a
* number to change the interval for the next run. `intervalMax` can be used to
Expand All @@ -49,56 +51,7 @@ export class JobRunner {
protected options!: Required<JobRunnerOptions>

constructor(options: JobRunnerOptions) {
let {
verbose,
intervalAccuracy,
intervalMax,
intervalInit,
startAfter,
times,
jitter,
} = options

const { interval } = options

if (verbose === undefined) {
verbose = true
}

if (intervalAccuracy === undefined) {
intervalAccuracy = true
}

if (intervalMax === undefined) {
intervalMax = Number.MAX_SAFE_INTEGER
}

if (intervalInit === undefined) {
intervalInit = interval
}

if (startAfter === undefined) {
startAfter = 0
}

if (times === undefined) {
times = Number.POSITIVE_INFINITY
}

if (jitter === undefined) {
jitter = 0
}

this.options = {
...options,
intervalAccuracy,
verbose,
intervalMax,
intervalInit,
startAfter,
times,
jitter,
}
this.parseOptions(options)
}

/**
Expand Down Expand Up @@ -133,10 +86,12 @@ export class JobRunner {
* The runner function. Returns a promise that resolves when the runner is
* finished.
*/
async run(): Promise<void> {
async run(options?: PartialJobRunnerOptions): Promise<void> {
if (this._isRunning) return
this._isRunning = true

this.parseOptions(options)

const {
name,
intervalFn,
Expand Down Expand Up @@ -247,4 +202,64 @@ export class JobRunner {
hasFinished(): Promise<void> {
return this._finished.promise
}

protected parseOptions(options?: PartialJobRunnerOptions): void {
if (!options) return

const mergedOptions = {
...this.options,
...options,
}

let {
verbose,
intervalAccuracy,
intervalMax,
intervalInit,
startAfter,
times,
jitter,
} = mergedOptions

const { interval } = mergedOptions

if (verbose === undefined) {
verbose = true
}

if (intervalAccuracy === undefined) {
intervalAccuracy = true
}

if (intervalMax === undefined) {
intervalMax = Number.MAX_SAFE_INTEGER
}

if (intervalInit === undefined) {
intervalInit = interval
}

if (startAfter === undefined) {
startAfter = 0
}

if (times === undefined) {
times = Number.POSITIVE_INFINITY
}

if (jitter === undefined) {
jitter = 0
}

this.options = {
...mergedOptions,
intervalAccuracy,
verbose,
intervalMax,
intervalInit,
startAfter,
times,
jitter,
}
}
}
Loading

0 comments on commit 05da833

Please sign in to comment.