|
20 | 20 | import { authHeader } from "../user/auth-header";
|
21 | 21 | import { config } from "../store/config";
|
22 | 22 | import { userService } from "../user/service";
|
23 |
| -import axios from "axios"; |
| 23 | +import axios, { AxiosResponse } from "axios"; |
24 | 24 | import { triggerCall } from "./admin";
|
25 | 25 |
|
| 26 | +interface JobJobType { |
| 27 | + Name: string; |
| 28 | + User: string; |
| 29 | + Utility: string; |
| 30 | + Environments: { |
| 31 | + Parameter: string |
| 32 | + } |
| 33 | + Parameters: { |
| 34 | + Parameter: string |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +interface JobExecutionType { |
| 39 | + Ended: string; |
| 40 | + ExitCode: number; |
| 41 | + Log: string; |
| 42 | + Id: string; |
| 43 | + Scheduled: string; |
| 44 | +} |
| 45 | + |
| 46 | +interface JobAdminType { |
| 47 | + Executions: JobExecutionType[]; |
| 48 | + Job: JobJobType; |
| 49 | + Status: string; |
| 50 | +} |
| 51 | + |
26 | 52 | export class JobAdmin {
|
27 |
| - private status: any; |
28 |
| - constructor(dbInput: any) { |
| 53 | + private status: JobAdminType; |
| 54 | + constructor(dbInput: JobAdminType) { |
29 | 55 | this.status = dbInput;
|
30 |
| - console.log("JOBS struct: "+JSON.stringify(dbInput)); |
31 | 56 | }
|
32 |
| - start() { |
33 |
| - console.log("Starting ..."); |
| 57 | + // Schedule the job |
| 58 | + async start(): Promise<AxiosResponse<any>> { |
34 | 59 | const getConfig = {
|
35 | 60 | headers: authHeader("application/json"),
|
36 | 61 | useCredentails: true,
|
37 | 62 | };
|
38 |
| - return axios |
39 |
| - .put(config.Url() + "/scheduler/job/" + this.status.Job.Name, {}, getConfig) |
40 |
| - .catch((error: any) => { |
41 |
| - if (error.response) { |
42 |
| - if (error.response.status == 401 || error.response.status == 403) { |
43 |
| - userService.logout(); |
44 |
| - location.reload(true); |
45 |
| - } |
| 63 | + try { |
| 64 | + return axios |
| 65 | + .put(config.Url() + "/scheduler/job/" + this.status.Job.Name, {}, getConfig); |
| 66 | + } |
| 67 | + catch (error) { |
| 68 | + if (error.response) { |
| 69 | + if (error.response.status == 401 || error.response.status == 403) { |
| 70 | + userService.logout(); |
| 71 | + location.reload(true); |
46 | 72 | }
|
47 |
| - throw error; |
48 |
| - }); |
| 73 | + } |
| 74 | + throw error; |
| 75 | + } |
49 | 76 | }
|
50 | 77 | name(): string {
|
51 | 78 | return this.status.Job.Name;
|
52 | 79 | }
|
53 |
| - delete() { |
| 80 | + async delete(): Promise<AxiosResponse<any>> { |
54 | 81 | const getConfig = {
|
55 | 82 | headers: authHeader("application/json"),
|
56 | 83 | useCredentails: true,
|
57 | 84 | };
|
58 |
| - return axios |
59 |
| - .delete(config.Url() + "/scheduler/job/" + this.status.Job.Name, getConfig) |
60 |
| - .catch((error: any) => { |
61 |
| - if (error.response) { |
62 |
| - if (error.response.status == 401 || error.response.status == 403) { |
63 |
| - userService.logout(); |
64 |
| - location.reload(true); |
65 |
| - } |
| 85 | + try { |
| 86 | + return axios |
| 87 | + .delete(config.Url() + "/scheduler/job/" + this.status.Job.Name, getConfig); |
| 88 | + } |
| 89 | + catch (error) { |
| 90 | + if (error.response) { |
| 91 | + if (error.response.status == 401 || error.response.status == 403) { |
| 92 | + userService.logout(); |
| 93 | + location.reload(true); |
66 | 94 | }
|
67 |
| - throw error; |
68 |
| - }); |
| 95 | + } |
| 96 | + throw error; |
| 97 | + } |
69 | 98 | }
|
70 |
| - delete_execution(id: string) { |
| 99 | + async delete_execution(id: string): Promise<AxiosResponse<any>> { |
71 | 100 | console.log("Starting ...");
|
72 | 101 | const getConfig = {
|
73 | 102 | headers: authHeader("application/json"),
|
74 | 103 | useCredentails: true,
|
75 | 104 | };
|
76 |
| - return axios |
77 |
| - .delete(config.Url() + "/scheduler/job/" + this.status.Job.Name + "/result/" + id, getConfig) |
78 |
| - .catch((error: any) => { |
79 |
| - if (error.response) { |
80 |
| - if (error.response.status == 401 || error.response.status == 403) { |
81 |
| - userService.logout(); |
82 |
| - location.reload(true); |
83 |
| - } |
| 105 | + try { |
| 106 | + return axios |
| 107 | + .delete(config.Url() + "/scheduler/job/" + this.status.Job.Name + "/result/" + id, getConfig); |
| 108 | + } |
| 109 | + catch (error) { |
| 110 | + if (error.response) { |
| 111 | + if (error.response.status == 401 || error.response.status == 403) { |
| 112 | + userService.logout(); |
| 113 | + location.reload(true); |
84 | 114 | }
|
85 |
| - throw error; |
86 |
| - }); |
| 115 | + } |
| 116 | + throw error; |
| 117 | + } |
87 | 118 |
|
88 | 119 | }
|
89 | 120 | }
|
90 | 121 |
|
91 |
| -export function insertJob(job: any): Promise<any> { |
| 122 | +// Insert job in REST server configuration. |
| 123 | +export async function insertJob(job: any): Promise<any> { |
92 | 124 | const getConfig = {
|
93 | 125 | headers: authHeader("application/json"),
|
94 | 126 | useCredentails: true,
|
95 | 127 | };
|
96 |
| - return axios |
97 |
| - .post(config.Url() + "/scheduler/job/", job, getConfig) |
98 |
| - .catch((error: any) => { |
99 |
| - if (error.response) { |
100 |
| - if (error.response.status == 401 || error.response.status == 403) { |
101 |
| - userService.logout(); |
102 |
| - location.reload(true); |
103 |
| - } |
| 128 | + try { |
| 129 | + return axios |
| 130 | + .post(config.Url() + "/scheduler/job/", job, getConfig); |
| 131 | + } |
| 132 | + catch (error) { |
| 133 | + if (error.response) { |
| 134 | + if (error.response.status == 401 || error.response.status == 403) { |
| 135 | + userService.logout(); |
| 136 | + location.reload(true); |
104 | 137 | }
|
105 |
| - throw error; |
106 |
| - }); |
| 138 | + } |
| 139 | + throw error; |
| 140 | + } |
107 | 141 | }
|
108 |
| -export function loadJobs(): Promise<any> { |
109 |
| - return triggerCall("/scheduler/job").then((response: any) => { |
110 |
| - const jobs = [] as any[]; |
111 |
| - response.JobDefinition.forEach((element: any) => { |
112 |
| - jobs.push(new JobAdmin(element)); |
113 |
| - }); |
114 |
| - return jobs; |
| 142 | + |
| 143 | +// Load all jobs available in REST server. Return array |
| 144 | +// of all jobs. |
| 145 | +export async function loadJobs(): Promise<any> { |
| 146 | + const response = await triggerCall("/scheduler/job"); |
| 147 | + const jobs = ([] as JobAdmin[]); |
| 148 | + response.JobDefinition.forEach((element: any) => { |
| 149 | + jobs.push(new JobAdmin(element)); |
115 | 150 | });
|
| 151 | + return jobs; |
116 | 152 | }
|
0 commit comments