-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dont show logs if no changes (#49)
* fix: types * feat: added equal helper * refactor: extracted TaskRunner types fix: show log message only if there are changes. * chore: fix linting * fix: missing line break
- Loading branch information
Showing
8 changed files
with
130 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { expect, describe, it } from "@jest/globals"; | ||
import { optionEquals } from "../helpers"; | ||
import { TaskRunnerOptions } from "../types"; | ||
|
||
describe("helpers", () => { | ||
it("Should return true if both options are equals", () => { | ||
const someOptions: TaskRunnerOptions = { | ||
workerID: "some-worker-id", | ||
domain: "mydomain", | ||
pollInterval: 1000, | ||
concurrency: 1, | ||
batchPollingTimeout: 1000, | ||
}; | ||
const otherOptions: TaskRunnerOptions = { | ||
...someOptions, | ||
}; | ||
expect(optionEquals(someOptions, otherOptions)).toBeTruthy(); | ||
|
||
expect(optionEquals(otherOptions, someOptions)).toBeTruthy(); | ||
}); | ||
|
||
it("Should return true if both options are equals", () => { | ||
const someOptions: TaskRunnerOptions = { | ||
workerID: "some-worker-id", | ||
domain: "mydomain", | ||
pollInterval: 1000, | ||
concurrency: 1, | ||
batchPollingTimeout: 1000, | ||
}; | ||
const otherOptions: TaskRunnerOptions = { | ||
...someOptions, | ||
batchPollingTimeout: 2000, | ||
}; | ||
expect(optionEquals(someOptions, otherOptions)).not.toBeTruthy(); | ||
|
||
expect(optionEquals(otherOptions, someOptions)).not.toBeTruthy(); | ||
}); | ||
it("Should return false if options are only equal in some properties", () => { | ||
const someOptions: TaskRunnerOptions = { | ||
workerID: "some-worker-id", | ||
domain: "mydomain", | ||
pollInterval: 1000, | ||
concurrency: 1, | ||
batchPollingTimeout: 1000, | ||
}; | ||
|
||
const someOptionsPrime: TaskRunnerOptions = { | ||
workerID: "some-worker-id", | ||
domain: "mydomain", | ||
}; | ||
|
||
expect(optionEquals(someOptions, someOptionsPrime)).not.toBeTruthy(); | ||
expect(optionEquals(someOptionsPrime, someOptions)).not.toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TaskRunnerOptions } from "./types"; | ||
type OptionEntries = Array< | ||
[keyof TaskRunnerOptions, string | number | undefined] | ||
>; | ||
|
||
|
||
/** | ||
* Compares if the new options are really new | ||
* @param oldOptions | ||
* @param newOptions | ||
*/ | ||
export const optionEquals = ( | ||
oldOptions: Partial<TaskRunnerOptions>, | ||
newOptions: Partial<TaskRunnerOptions> | ||
) => { | ||
const newOptionEntries = Object.entries(newOptions) as OptionEntries; | ||
const oldOptionsEntries = Object.entries(oldOptions) as OptionEntries; | ||
|
||
return newOptionEntries.length === oldOptionsEntries.length && newOptionEntries.every( | ||
([key, value]) => (oldOptions[key] as unknown) === value | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./TaskRunner" | ||
export * from "./TaskManager" | ||
export * from "./Worker" | ||
export * from "./TaskRunner"; | ||
export * from "./TaskManager"; | ||
export * from "./Worker"; | ||
export * from "./types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ConductorLogger } from "../common"; | ||
import type { ConductorWorker } from "./Worker"; | ||
import type { Task, TaskResourceService } from "../common/open-api"; | ||
|
||
export type TaskErrorHandler = (error: Error, task?: Task) => void; | ||
export interface TaskRunnerOptions { | ||
workerID: string; | ||
domain: string | undefined; | ||
pollInterval?: number; | ||
concurrency?: number; | ||
batchPollingTimeout?: number; | ||
} | ||
export interface RunnerArgs { | ||
worker: ConductorWorker; | ||
taskResource: TaskResourceService; | ||
options: TaskRunnerOptions; | ||
logger?: ConductorLogger; | ||
onError?: TaskErrorHandler; | ||
concurrency?: number; | ||
} |