8000 autostart/autostop: move to traditional 5-valued cron string for compatibility by johnstcn · Pull Request #1049 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

autostart/autostop: move to traditional 5-valued cron string for compatibility #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension 8000

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
web: remove unused function expandScheduleCronString
  • Loading branch information
johnstcn committed Apr 16, 2022
commit 077284f9aa7958fd745c51bed3baf4222d872345
4 changes: 2 additions & 2 deletions site/src/components/Workspace/WorkspaceSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Box from "@material-ui/core/Box"
import Typography from "@material-ui/core/Typography"
import cronstrue from "cronstrue"
import React from "react"
import { expandScheduleCronString, extractTimezone } from "../../util/schedule"
import { stripTimezone, extractTimezone } from "../../util/schedule"
import { WorkspaceSection } from "./WorkspaceSection"

const Language = {
Expand All @@ -26,7 +26,7 @@ const Language = {
},
cronHumanDisplay: (schedule: string): string => {
if (schedule) {
return cronstrue.toString(expandScheduleCronString(schedule), { throwExceptionOnParseError: false })
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
}
return "Manual"
},
Expand Down
12 changes: 1 addition & 11 deletions site/src/util/schedule.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expandScheduleCronString, extractTimezone, stripTimezone } from "./schedule"
import { extractTimezone, stripTimezone } from "./schedule"

describe("util/schedule", () => {
describe("stripTimezone", () => {
Expand All @@ -20,14 +20,4 @@ describe("util/schedule", () => {
expect(extractTimezone(input)).toBe(expected)
})
})

describe("expandScheduleCronString", () => {
it.each BDD2 <[string, string]>([
["CRON_TZ=Canada/Eastern 30 9 1-5", "30 9 * * 1-5"],
["CRON_TZ=America/Central 0 8 1,2,4,5", "0 8 * * 1,2,4,5"],
["30 9 1-5", "30 9 * * 1-5"],
])(`expandScheduleCronString(%p) returns %p`, (input, expected) => {
expect(expandScheduleCronString(input)).toBe(expected)
})
})
})
22 changes: 0 additions & 22 deletions site/src/util/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,3 @@ export const extractTimezone = (raw: string): string => {
return DEFAULT_TIMEZONE
}
}

/**
* expandScheduleCronString ensures a Schedule is expanded to a valid 5-value
* cron string by inserting '*' in month and day positions. If there is a
* leading timezone, it is removed.
*
* @example
* expandScheduleCronString("30 9 1-5") // -> "30 9 * * 1-5"
*/
export const expandScheduleCronString = (schedule: string): string => {
const prepared = stripTimezone(schedule).trim()

const parts = prepared.split(" ")

while (parts.length < 5) {
// insert '*' in the second to last position
// ie [a, b, c] --> [a, b, *, c]
parts.splice(parts.length - 1, 0, "*")
}

return parts.join(" ")
}
0