1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/components/+workloads-cronjobs/cronjob.store.ts
Sebastian Malton b1ff34879a cleanup Lens repo with tighter linting
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
2020-07-09 17:00:23 -04:00

36 lines
1.0 KiB
TypeScript

import { KubeObjectStore } from "../../kube-object.store";
import { autobind } from "../../utils";
import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api";
import { jobStore } from "../+workloads-jobs/job.store";
import { apiManager } from "../../api/api-manager";
import { Dictionary } from "lodash";
@autobind()
export class CronJobStore extends KubeObjectStore<CronJob> {
api = cronJobApi
getStatuses(cronJobs?: CronJob[]): Dictionary<number> {
const status = { failed: 0, running: 0 };
cronJobs.forEach(cronJob => {
if (cronJob.spec.suspend) {
status.failed++;
} else {
status.running++;
}
});
return status;
}
getActiveJobsNum(cronJob: CronJob): number {
// Active jobs are jobs without any condition 'Complete' nor 'Failed'
const jobs = jobStore.getJobsByOwner(cronJob);
if (!jobs.length) {
return 0;
}
return jobs.filter(job => !job.getCondition()).length;
}
}
export const cronJobStore = new CronJobStore();
apiManager.registerStore(cronJobApi, cronJobStore);