Skip to content

Commit

Permalink
feat:cronjob timezone (#3948)
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Sep 18, 2023
1 parent 6b0a03a commit 3c5445c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions frontend/providers/cronjob/src/types/job.d.ts
Expand Up @@ -104,3 +104,14 @@ export type JobList = {
startTimeTimestamp: number;
}[];
};

export type CronJobAnnotations = {
timeZone: string;
enableNumberCopies: string;
enableResources: string;
cpu: string;
memory: string;
launchpadName: string;
launchpadId: string;
replicas: string;
};
10 changes: 8 additions & 2 deletions frontend/providers/cronjob/src/utils/adapt.ts
@@ -1,6 +1,12 @@
import { CronJobStatusMap, StatusEnum } from '@/constants/job';
import { AppListItemType } from '@/types/app';
import { CronJobEditType, CronJobListItemType, JobEvent, JobList } from '@/types/job';
import {
CronJobAnnotations,
CronJobEditType,
CronJobListItemType,
JobEvent,
JobList
} from '@/types/job';
import { cpuFormatToM, cron2Time, formatPodTime, memoryFormatToMi } from '@/utils/tools';
import {
CoreV1EventList,
Expand Down Expand Up @@ -50,7 +56,7 @@ export const adaptCronJobDetail = async (job: V1CronJob): Promise<CronJobEditTyp
.toString();
const status_str = job.spec?.suspend ? StatusEnum.Stopped : StatusEnum.Running;
const { cpu, enableNumberCopies, enableResources, launchpadId, launchpadName, memory, replicas } =
job.metadata?.annotations || {};
job.metadata?.annotations as CronJobAnnotations;

const getUrl = (): string => {
const commands = job.spec?.jobTemplate?.spec?.template?.spec?.containers?.[0]?.args;
Expand Down
4 changes: 3 additions & 1 deletion frontend/providers/cronjob/src/utils/json2Yaml.ts
@@ -1,10 +1,11 @@
import { CronJobEditType } from '@/types/job';
import { str2Num } from '@/utils/tools';
import { getUserTimeZone, str2Num } from '@/utils/tools';
import yaml from 'js-yaml';
import { getUserServiceAccount } from './user';

export const json2CronJob = (data: CronJobEditType) => {
const serviceAccount = getUserServiceAccount();
const timeZone = getUserTimeZone();

const metadata = {
name: data.jobName,
Expand Down Expand Up @@ -106,6 +107,7 @@ export const json2CronJob = (data: CronJobEditType) => {
schedule: data.schedule,
successfulJobsHistoryLimit: 3,
failedJobsHistoryLimit: 3,
timeZone: timeZone,
jobTemplate: {
activeDeadlineSeconds: 600,
spec: {
Expand Down
5 changes: 5 additions & 0 deletions frontend/providers/cronjob/src/utils/tools.ts
Expand Up @@ -330,3 +330,8 @@ export const obj2Query = (obj: Record<string, string | number>) => {

return str.slice(0, str.length - 1);
};

export const getUserTimeZone = () => {
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
return userTimeZone;
};

0 comments on commit 3c5445c

Please sign in to comment.