Skip to content

Commit

Permalink
fix: use the server timezone to parse the cron expression (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnochoo authored Nov 6, 2024
1 parent 22fe495 commit 93c3710
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 45 deletions.
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {
APIBaseURL string // Base URL for API
Debug bool // Enable debug mode (verbose logging)
LogFormat string // Log format
TimeZone string // The server time zone
}

type TLS struct {
Expand Down Expand Up @@ -178,6 +179,7 @@ func bindEnvs() {
_ = viper.BindEnv("navbarColor", "DAGU_NAVBAR_COLOR")
_ = viper.BindEnv("navbarTitle", "DAGU_NAVBAR_TITLE")
_ = viper.BindEnv("apiBaseURL", "DAGU_API_BASE_URL")
_ = viper.BindEnv("timeZone", "DAGU_TIME_ZONE")

// Basic authentication
_ = viper.BindEnv("isBasicAuth", "DAGU_IS_BASICAUTH")
Expand Down
1 change: 1 addition & 0 deletions internal/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func New(cfg *config.Config, lg logger.Logger, cli client.Client) *server.Server
NavbarColor: cfg.NavbarColor,
NavbarTitle: cfg.NavbarTitle,
APIBaseURL: cfg.APIBaseURL,
TimeZone: cfg.TimeZone,
}

if cfg.IsAuthToken {
Expand Down
2 changes: 2 additions & 0 deletions internal/frontend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type NewServerArgs struct {
NavbarColor string
NavbarTitle string
APIBaseURL string
TimeZone string
}

type BasicAuth struct {
Expand Down Expand Up @@ -92,6 +93,7 @@ func New(params NewServerArgs) *Server {
NavbarColor: params.NavbarColor,
NavbarTitle: params.NavbarTitle,
APIBaseURL: params.APIBaseURL,
TimeZone: params.TimeZone,
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/frontend/server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type funcsConfig struct {
NavbarColor string
NavbarTitle string
APIBaseURL string
TimeZone string
}

func defaultFunctions(cfg funcsConfig) template.FuncMap {
Expand All @@ -80,6 +81,9 @@ func defaultFunctions(cfg funcsConfig) template.FuncMap {
"apiURL": func() string {
return cfg.APIBaseURL
},
"timeZone": func() string {
return cfg.TimeZone
},
}
}

Expand Down
43 changes: 21 additions & 22 deletions internal/frontend/templates/base.gohtml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
{{define "base"}}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{navbarTitle}}</title>
<script>
function getConfig() {
return {
apiURL: "{{ apiURL }}",
title: "{{ navbarTitle }}",
navbarColor: "{{ navbarColor }}",
version: "{{ version }}",
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ navbarTitle }}</title>
<script>
function getConfig() {
return {
apiURL: "{{ apiURL }}",
title: "{{ navbarTitle }}",
navbarColor: "{{ navbarColor }}",
version: "{{ version }}",
timeZone: "{{ timeZone }}",
};
}
}
</script>
<script defer="defer" src="/assets/bundle.js?v={{ version }}"></script>
</head>
<body>
{{template "content" .}}
</body>

</script>
<script defer="defer" src="/assets/bundle.js?v={{ version }}"></script>
</head>
<body>
{{template "content" .}}
</body>
</html>
{{ end }}
{{ end }}
1 change: 1 addition & 0 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
title: '',
navbarColor: '',
version: '',
timeZone: '',
};
}
</script>
Expand Down
1 change: 1 addition & 0 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Config = {
apiURL: string;
title: string;
navbarColor: string;
timeZone: string;
version: string;
};

Expand Down
48 changes: 28 additions & 20 deletions ui/src/components/molecules/DAGTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ const defaultColumns = [
}),
columnHelper.accessor('Type', {
id: 'Schedule',
header: 'Schedule',
header: getConfig().timeZone
? `Schedule in ${getConfig().timeZone}`
: 'Schedule',
enableSorting: true,
cell: (props) => {
const data = props.row.original!;
Expand Down Expand Up @@ -389,7 +391,15 @@ const defaultColumns = [
}),
];

function DAGTable({ DAGs = [], group = '', refreshFn, searchText, handleSearchTextChange, searchTag, handleSearchTagChange }: Props) {
function DAGTable({
DAGs = [],
group = '',
refreshFn,
searchText,
handleSearchTextChange,
searchTag,
handleSearchTagChange,
}: Props) {
const [columns] = React.useState<typeof defaultColumns>(() => [
...defaultColumns,
]);
Expand Down Expand Up @@ -444,7 +454,7 @@ function DAGTable({ DAGs = [], group = '', refreshFn, searchText, handleSearchTe
const instance = useReactTable<DAGRow>({
data,
columns,
getSubRows: (row) =>row.subRows,
getSubRows: (row) => row.subRows,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
Expand Down Expand Up @@ -497,21 +507,19 @@ function DAGTable({ DAGs = [], group = '', refreshFn, searchText, handleSearchTe
limitTags={1}
value={searchTag}
freeSolo
options={
DAGs.reduce<string[]>((acc, dag) => {
if (dag.Type == DAGDataType.DAG) {
const tags = dag.DAGStatus.DAG.Tags;
if (tags) {
tags.forEach((tag) => {
if (!acc.includes(tag)) {
acc.push(tag);
}
});
}
options={DAGs.reduce<string[]>((acc, dag) => {
if (dag.Type == DAGDataType.DAG) {
const tags = dag.DAGStatus.DAG.Tags;
if (tags) {
tags.forEach((tag) => {
if (!acc.includes(tag)) {
acc.push(tag);
}
});
}
return acc;
}, [])
}
}
return acc;
}, [])}
onChange={(_, value) => {
const v = value || '';
handleSearchTagChange(v);
Expand Down Expand Up @@ -558,9 +566,9 @@ function DAGTable({ DAGs = [], group = '', refreshFn, searchText, handleSearchTe
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
header.column.columnDef.header,
header.getContext()
)}
{{
asc: (
<ArrowUpward
Expand Down
13 changes: 10 additions & 3 deletions ui/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ export function getNextSchedule(data: WorkflowListItem): number {
if (!schedules || schedules.length == 0 || data.Suspended) {
return Number.MAX_SAFE_INTEGER;
}
const datesToRun = schedules.map((s) =>
cronParser.parseExpression(s.Expression).next()
);
const tz = getConfig().timeZone;
const datesToRun = schedules.map((s) => {
const expression = tz
? cronParser.parseExpression(s.Expression, {
currentDate: new Date(),
tz,
})
: cronParser.parseExpression(s.Expression);
return expression.next();
});
const sorted = datesToRun.sort((a, b) => a.getTime() - b.getTime());
return sorted[0].getTime() / 1000;
}
Expand Down

0 comments on commit 93c3710

Please sign in to comment.