Skip to content

Commit

Permalink
fix: generate new job api and update job plugin new api
Browse files Browse the repository at this point in the history
  • Loading branch information
collinlokken committed Nov 27, 2023
1 parent e03b255 commit 4d5b53f
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/dm-core-plugins/src/job/JobControlButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export const JobControlButton = (props: {
<Button
ref={buttonRef}
onClick={() => {
if (exists) return remove()
if (exists) {
remove()
}
createJob()
}}
style={{ width: '7rem' }}
Expand Down
2 changes: 1 addition & 1 deletion packages/dm-core-plugins/src/job/JobLogsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LogBlock } from './LogBlock'
type AboutDialogProps = {
isOpen: boolean
setIsOpen: (newValue: boolean) => void
logs: string
logs: string[]
error: ErrorResponse | undefined
result: GetJobResultResponse | null
}
Expand Down
17 changes: 16 additions & 1 deletion packages/dm-core-plugins/src/job/JobPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import React, {
useMemo,
useState,
} from 'react'
import { Button, Chip, Icon, Switch } from '@equinor/eds-core-react'
import {
Button,
Chip,
Icon,
LinearProgress,
Switch,
} from '@equinor/eds-core-react'
import { JobControlButton } from './JobControlButton'
import { expand_screen, refresh } from '@equinor/eds-icons'
import styled from 'styled-components'
Expand Down Expand Up @@ -103,6 +109,7 @@ export const JobPlugin = (props: IUIPlugin & { config: JobPluginConfig }) => {
fetchResult,
fetchStatusAndLogs,
logs,
progress,
status,
exists,
remove,
Expand Down Expand Up @@ -200,6 +207,14 @@ export const JobPlugin = (props: IUIPlugin & { config: JobPluginConfig }) => {
</Button>
<Chip variant={getVariant(status)}>{status}</Chip>
</JobButtonWrapper>
<div style={{ display: 'flex', alignItems: 'center', width: '50%' }}>
<LinearProgress
aria-label="Progress bar label"
value={progress * 100}
variant="determinate"
/>
<pre>{progress * 100}</pre>
</div>
<JobLogsDialog
isOpen={showLogs}
setIsOpen={setShowLogs}
Expand Down
28 changes: 17 additions & 11 deletions packages/dm-core/src/hooks/useJob.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface IUseJob {
status: JobStatus
remove: () => Promise<string | null>
fetchResult: () => any // TODO: Type set this return value
logs: string
logs: string[]
progress: GLfloat
isLoading: boolean
error: ErrorResponse | undefined
exists: boolean
Expand Down Expand Up @@ -75,7 +76,8 @@ interface IUseJob {
*/
export function useJob(entityId?: string, jobId?: string): IUseJob {
const [hookJobId, setHookJobId] = useState<string | undefined>(jobId)
const [logs, setLogs] = useState<string>('No logs fetched')
const [logs, setLogs] = useState<string[]>(['No logs fetched'])
const [progress, setProgress] = useState<GLfloat>(0.0)
const [status, setStatus] = useState<JobStatus>(JobStatus.Unknown)
const [isLoading, setIsLoading] = useState<boolean>(true)
const [error, setError] = useState<ErrorResponse>()
Expand Down Expand Up @@ -110,6 +112,7 @@ export function useJob(entityId?: string, jobId?: string): IUseJob {
// When hookJobId changes, we register an interval to check status.
// The interval is deregistered if the status of the job is not "Running"
useEffect(() => {
console.log(hookJobId)
if (!hookJobId) return
statusIntervalId = setInterval(fetchStatusAndLogs, 5000)
return () => clearInterval(statusIntervalId)
Expand All @@ -131,7 +134,7 @@ export function useJob(entityId?: string, jobId?: string): IUseJob {
.startJob({ jobDmssId: entityId })
.then((response: AxiosResponse<StartJobResponse>) => {
setHookJobId(response.data.uid)
setLogs(response.data.message)
setLogs([response.data.message])
setError(undefined)
setStatus(JobStatus.Running)
return response.data
Expand All @@ -149,25 +152,25 @@ export function useJob(entityId?: string, jobId?: string): IUseJob {
async function fetchStatusAndLogs(): Promise<StatusJobResponse | null> {
if (!hookJobId) {
clearInterval(statusIntervalId)
const message = 'The job has not been started'
setLogs(message)
const log = ['The job has not been started']
setLogs(log)
setStatus(JobStatus.NotStarted)
return Promise.resolve({
status: JobStatus.NotStarted,
log: message,
message: message,
log: log,
percentage: 0.0,
})
}

setIsLoading(true)

return dmJobApi
.jobStatus({ jobUid: hookJobId })
.then((response: AxiosResponse<StatusJobResponse>) => {
if (response.data.percentage) {
setProgress(response.data.percentage)
}
setLogs(
response.data.log ??
response.data.message ??
'No logs or status returned from job handler'
response.data.log ?? ['No logs or status returned from job handler']
)
if (response.data.status !== status) setStatus(response.data.status)
if (
Expand Down Expand Up @@ -209,6 +212,8 @@ export function useJob(entityId?: string, jobId?: string): IUseJob {
.finally(() => {
setError(undefined)
setIsLoading(false)
setLogs([])
setProgress(0.0)
})
}

Expand Down Expand Up @@ -238,6 +243,7 @@ export function useJob(entityId?: string, jobId?: string): IUseJob {
remove,
fetchResult,
logs,
progress,
isLoading,
error,
exists: !!hookJobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ models/error-response.ts
models/get-job-result-response.ts
models/index.ts
models/job-status.ts
models/progress.ts
models/start-job-response.ts
models/status-job-response.ts
models/update-job-progress-response.ts
2 changes: 1 addition & 1 deletion packages/dm-core/src/services/api/configs/gen-job/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
120 changes: 119 additions & 1 deletion packages/dm-core/src/services/api/configs/gen-job/api/dmjobs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -26,9 +26,13 @@ import { ErrorResponse } from '../models';
// @ts-ignore
import { GetJobResultResponse } from '../models';
// @ts-ignore
import { Progress } from '../models';
// @ts-ignore
import { StartJobResponse } from '../models';
// @ts-ignore
import { StatusJobResponse } from '../models';
// @ts-ignore
import { UpdateJobProgressResponse } from '../models';
/**
* DMJobsApi - axios parameter creator
* @export
Expand Down Expand Up @@ -182,6 +186,57 @@ export const DMJobsApiAxiosParamCreator = function (configuration?: Configuratio
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Update the progress of the job. - **job_uid**: the job API\'s internal uid for the job. - **progress**: progress object with percentage and logs
* @summary Progress
* @param {string} jobUid
* @param {boolean} forceLog
* @param {Progress} progress
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateJobProgress: async (jobUid: string, forceLog: boolean, progress: Progress, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'jobUid' is not null or undefined
assertParamExists('updateJobProgress', 'jobUid', jobUid)
// verify required parameter 'forceLog' is not null or undefined
assertParamExists('updateJobProgress', 'forceLog', forceLog)
// verify required parameter 'progress' is not null or undefined
assertParamExists('updateJobProgress', 'progress', progress)
const localVarPath = `/{job_uid}`
.replace(`{${"job_uid"}}`, encodeURIComponent(String(jobUid)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication OAuth2AuthorizationCodeBearer required
// oauth required
await setOAuthToObject(localVarHeaderParameter, "OAuth2AuthorizationCodeBearer", [], configuration)

if (forceLog !== undefined) {
localVarQueryParameter['force_log'] = forceLog;
}



localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(progress, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
Expand Down Expand Up @@ -241,6 +296,19 @@ export const DMJobsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.startJob(jobDmssId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Update the progress of the job. - **job_uid**: the job API\'s internal uid for the job. - **progress**: progress object with percentage and logs
* @summary Progress
* @param {string} jobUid
* @param {boolean} forceLog
* @param {Progress} progress
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async updateJobProgress(jobUid: string, forceLog: boolean, progress: Progress, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UpdateJobProgressResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.updateJobProgress(jobUid, forceLog, progress, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

Expand Down Expand Up @@ -291,6 +359,16 @@ export const DMJobsApiFactory = function (configuration?: Configuration, basePat
startJob(requestParameters: DMJobsApiStartJobRequest, options?: AxiosRequestConfig): AxiosPromise<StartJobResponse> {
return localVarFp.startJob(requestParameters.jobDmssId, options).then((request) => request(axios, basePath));
},
/**
* Update the progress of the job. - **job_uid**: the job API\'s internal uid for the job. - **progress**: progress object with percentage and logs
* @summary Progress
* @param {DMJobsApiUpdateJobProgressRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateJobProgress(requestParameters: DMJobsApiUpdateJobProgressRequest, options?: AxiosRequestConfig): AxiosPromise<UpdateJobProgressResponse> {
return localVarFp.updateJobProgress(requestParameters.jobUid, requestParameters.forceLog, requestParameters.progress, options).then((request) => request(axios, basePath));
},
};
};

Expand Down Expand Up @@ -350,6 +428,34 @@ export interface DMJobsApiStartJobRequest {
readonly jobDmssId: string
}

/**
* Request parameters for updateJobProgress operation in DMJobsApi.
* @export
* @interface DMJobsApiUpdateJobProgressRequest
*/
export interface DMJobsApiUpdateJobProgressRequest {
/**
*
* @type {string}
* @memberof DMJobsApiUpdateJobProgress
*/
readonly jobUid: string

/**
*
* @type {boolean}
* @memberof DMJobsApiUpdateJobProgress
*/
readonly forceLog: boolean

/**
*
* @type {Progress}
* @memberof DMJobsApiUpdateJobProgress
*/
readonly progress: Progress
}

/**
* DMJobsApi - object-oriented interface
* @export
Expand Down Expand Up @@ -404,4 +510,16 @@ export class DMJobsApi extends BaseAPI {
public startJob(requestParameters: DMJobsApiStartJobRequest, options?: AxiosRequestConfig) {
return DMJobsApiFp(this.configuration).startJob(requestParameters.jobDmssId, options).then((request) => request(this.axios, this.basePath));
}

/**
* Update the progress of the job. - **job_uid**: the job API\'s internal uid for the job. - **progress**: progress object with percentage and logs
* @summary Progress
* @param {DMJobsApiUpdateJobProgressRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DMJobsApi
*/
public updateJobProgress(requestParameters: DMJobsApiUpdateJobProgressRequest, options?: AxiosRequestConfig) {
return DMJobsApiFp(this.configuration).updateJobProgress(requestParameters.jobUid, requestParameters.forceLog, requestParameters.progress, options).then((request) => request(this.axios, this.basePath));
}
}
2 changes: 1 addition & 1 deletion packages/dm-core/src/services/api/configs/gen-job/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/dm-core/src/services/api/configs/gen-job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Modelling Job API
* REST API used with the Data Modelling framework to schedule jobs
*
* The version of the OpenAPI document: 0.1.0
* The version of the OpenAPI document: 1.3.5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './error-response';
export * from './get-job-result-response';
export * from './job-status';
export * from './progress';
export * from './start-job-response';
export * from './status-job-response';
export * from './update-job-progress-response';
Loading

0 comments on commit 4d5b53f

Please sign in to comment.