Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add support taskCount on createJob
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksandr-Kasko-JazzTeam committed Mar 4, 2024
1 parent 139aff8 commit 1b81af0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.2.8
- Add support taskCount on createJob

#### 1.2.1
- Update dependencies
- Add test for running a job
Expand Down
47 changes: 30 additions & 17 deletions src/lib/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export class Jobs {
const {
jobName,
image,
command = [],
args = [],
env = [],
timeoutSeconds = 600,
maxRetries = 3,
cpu = "1000m",
memory = "512Mi"
command,
args,
env,
timeoutSeconds,
maxRetries,
taskCount,
cpu,
memory
} = createJobArgs;
const config = await getAxiosConfig(this.projectName, this.serviceAccount);
config.headers!["Content-Type"] = 'application/json';
Expand All @@ -44,7 +45,7 @@ export class Jobs {
spec: {
template: {
spec: {
taskCount: 1,
taskCount: taskCount || 1,
template: {
spec: {
containers: [
Expand All @@ -55,16 +56,16 @@ export class Jobs {
env,
resources: {
limits: {
cpu,
memory
cpu: cpu || "1000m",
memory: memory || "512Mi"
}
},

}
],
timeoutSeconds: timeoutSeconds.toString(),
timeoutSeconds: (timeoutSeconds || 600).toString(),
serviceAccountName: this.serviceAccount,
maxRetries
maxRetries: maxRetries || 3
}
}
}
Expand All @@ -86,7 +87,10 @@ export class Jobs {
};
const axios = new Axios({});
try {
const response = await axios.get(JOBS_API_HOST + this.projectName + '/executions', config);
const response = await axios.get(
JOBS_API_HOST + this.projectName + '/executions',
config
);
const data = JSON.parse(response.data);
if (data.items?.length > 0) {
const runningCount = data.items[0]?.status?.runningCount || 0;
Expand All @@ -101,7 +105,11 @@ export class Jobs {
try {
const config = await getAxiosConfig(this.projectName, this.serviceAccount);
const axios = new Axios({});
const response = await axios.post(JOBS_API_HOST + this.projectName + '/jobs/' + jobId + ':run', "", config);
const response = await axios.post(
JOBS_API_HOST + this.projectName + '/jobs/' + jobId + ':run',
"",
config
);
return response.status == 200;
} catch (e) {
return false;
Expand All @@ -127,7 +135,10 @@ export class Jobs {
async deleteJob(jobId: string): Promise<Operation> {
const config = await getAxiosConfig(this.projectName, this.serviceAccount);
const axios = new Axios({});
const axiosResponse = await axios.delete(JOBS_API_HOST + this.projectName + '/jobs/' + jobId, config);
const axiosResponse = await axios.delete(
JOBS_API_HOST + this.projectName + '/jobs/' + jobId,
config
);
const parsedData = JSON.parse(axiosResponse.data);
if (parsedData.error) throw Error(JSON.stringify(parsedData.error));
return parsedData;
Expand All @@ -152,8 +163,10 @@ export class Jobs {

return {
executionCount: job.status?.executionCount || 0,
lastFailedCount: items?.slice(0, take).filter(execution => (execution?.status?.failedCount || 0) > 0).length || 0,
lastExecutionStatus: items[0]?.status?.conditions?.find(condition => condition.type == "Completed")?.status || "Unknown",
lastFailedCount: items?.slice(0, take)
.filter(execution => (execution?.status?.failedCount || 0) > 0).length || 0,
lastExecutionStatus: items[0]?.status?.conditions
?.find(condition => condition.type == "Completed")?.status || "Unknown",
startTime: items[0]?.status?.startTime,
completionTime: items[0]?.status?.completionTime
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ export type Status = {
export type CreateJobArgs = {
jobName: string;
image: string;
command: string[];
args: string[];
env: EnvVar[];
command?: string[];
args?: string[];
env?: EnvVar[];
timeoutSeconds?: number;
maxRetries?: number;
taskCount?: number;
cpu?: "1000m"|"2000m"|"4000m";
memory?: "512Mi" | "1Gi" | "2Gi" | "4Gi" | "8Gi" | "16Gi"
}

0 comments on commit 1b81af0

Please sign in to comment.