-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12280 from Budibase/fix/update-bull-queue-parameters
Restore bull parameter changes + reduce Redis config complexity
- Loading branch information
Showing
10 changed files
with
142 additions
and
54 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
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,49 @@ | ||
export enum DurationType { | ||
MILLISECONDS = "milliseconds", | ||
SECONDS = "seconds", | ||
MINUTES = "minutes", | ||
HOURS = "hours", | ||
DAYS = "days", | ||
} | ||
|
||
const conversion: Record<DurationType, number> = { | ||
milliseconds: 1, | ||
seconds: 1000, | ||
minutes: 60 * 1000, | ||
hours: 60 * 60 * 1000, | ||
days: 24 * 60 * 60 * 1000, | ||
} | ||
|
||
export class Duration { | ||
static convert(from: DurationType, to: DurationType, duration: number) { | ||
const milliseconds = duration * conversion[from] | ||
return milliseconds / conversion[to] | ||
} | ||
|
||
static from(from: DurationType, duration: number) { | ||
return { | ||
to: (to: DurationType) => { | ||
return Duration.convert(from, to, duration) | ||
}, | ||
toMs: () => { | ||
return Duration.convert(from, DurationType.MILLISECONDS, duration) | ||
}, | ||
} | ||
} | ||
|
||
static fromSeconds(duration: number) { | ||
return Duration.from(DurationType.SECONDS, duration) | ||
} | ||
|
||
static fromMinutes(duration: number) { | ||
return Duration.from(DurationType.MINUTES, duration) | ||
} | ||
|
||
static fromHours(duration: number) { | ||
return Duration.from(DurationType.HOURS, duration) | ||
} | ||
|
||
static fromDays(duration: number) { | ||
return Duration.from(DurationType.DAYS, duration) | ||
} | ||
} |
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 "./hashing" | ||
export * from "./utils" | ||
export * from "./stringUtils" | ||
export * from "./Duration" |
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,19 @@ | ||
import { Duration, DurationType } from "../Duration" | ||
|
||
describe("duration", () => { | ||
it("should convert minutes to milliseconds", () => { | ||
expect(Duration.fromMinutes(5).toMs()).toBe(300000) | ||
}) | ||
|
||
it("should convert seconds to milliseconds", () => { | ||
expect(Duration.fromSeconds(30).toMs()).toBe(30000) | ||
}) | ||
|
||
it("should convert days to milliseconds", () => { | ||
expect(Duration.fromDays(1).toMs()).toBe(86400000) | ||
}) | ||
|
||
it("should convert minutes to days", () => { | ||
expect(Duration.fromMinutes(1440).to(DurationType.DAYS)).toBe(1) | ||
}) | ||
}) |
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