refactor(server): send job command (#2777)

* refactor: send job command

* chore: open api
This commit is contained in:
Jason Rasmussen 2023-06-16 15:36:07 -04:00 committed by GitHub
parent f04e47803c
commit fde410e2ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 44 deletions

View File

@ -125,7 +125,7 @@ Class | Method | HTTP request | Description
*AuthenticationApi* | [**logoutAuthDevices**](doc//AuthenticationApi.md#logoutauthdevices) | **DELETE** /auth/devices | *AuthenticationApi* | [**logoutAuthDevices**](doc//AuthenticationApi.md#logoutauthdevices) | **DELETE** /auth/devices |
*AuthenticationApi* | [**validateAccessToken**](doc//AuthenticationApi.md#validateaccesstoken) | **POST** /auth/validateToken | *AuthenticationApi* | [**validateAccessToken**](doc//AuthenticationApi.md#validateaccesstoken) | **POST** /auth/validateToken |
*JobApi* | [**getAllJobsStatus**](doc//JobApi.md#getalljobsstatus) | **GET** /jobs | *JobApi* | [**getAllJobsStatus**](doc//JobApi.md#getalljobsstatus) | **GET** /jobs |
*JobApi* | [**sendJobCommand**](doc//JobApi.md#sendjobcommand) | **PUT** /jobs/{jobId} | *JobApi* | [**sendJobCommand**](doc//JobApi.md#sendjobcommand) | **PUT** /jobs/{id} |
*OAuthApi* | [**callback**](doc//OAuthApi.md#callback) | **POST** /oauth/callback | *OAuthApi* | [**callback**](doc//OAuthApi.md#callback) | **POST** /oauth/callback |
*OAuthApi* | [**generateConfig**](doc//OAuthApi.md#generateconfig) | **POST** /oauth/config | *OAuthApi* | [**generateConfig**](doc//OAuthApi.md#generateconfig) | **POST** /oauth/config |
*OAuthApi* | [**link**](doc//OAuthApi.md#link) | **POST** /oauth/link | *OAuthApi* | [**link**](doc//OAuthApi.md#link) | **POST** /oauth/link |

View File

@ -10,7 +10,7 @@ All URIs are relative to */api*
Method | HTTP request | Description Method | HTTP request | Description
------------- | ------------- | ------------- ------------- | ------------- | -------------
[**getAllJobsStatus**](JobApi.md#getalljobsstatus) | **GET** /jobs | [**getAllJobsStatus**](JobApi.md#getalljobsstatus) | **GET** /jobs |
[**sendJobCommand**](JobApi.md#sendjobcommand) | **PUT** /jobs/{jobId} | [**sendJobCommand**](JobApi.md#sendjobcommand) | **PUT** /jobs/{id} |
# **getAllJobsStatus** # **getAllJobsStatus**
@ -65,7 +65,7 @@ This endpoint does not need any parameter.
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **sendJobCommand** # **sendJobCommand**
> JobStatusDto sendJobCommand(jobId, jobCommandDto) > JobStatusDto sendJobCommand(id, jobCommandDto)
@ -88,11 +88,11 @@ import 'package:openapi/api.dart';
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction); //defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = JobApi(); final api_instance = JobApi();
final jobId = ; // JobName | final id = ; // JobName |
final jobCommandDto = JobCommandDto(); // JobCommandDto | final jobCommandDto = JobCommandDto(); // JobCommandDto |
try { try {
final result = api_instance.sendJobCommand(jobId, jobCommandDto); final result = api_instance.sendJobCommand(id, jobCommandDto);
print(result); print(result);
} catch (e) { } catch (e) {
print('Exception when calling JobApi->sendJobCommand: $e\n'); print('Exception when calling JobApi->sendJobCommand: $e\n');
@ -103,7 +103,7 @@ try {
Name | Type | Description | Notes Name | Type | Description | Notes
------------- | ------------- | ------------- | ------------- ------------- | ------------- | ------------- | -------------
**jobId** | [**JobName**](.md)| | **id** | [**JobName**](.md)| |
**jobCommandDto** | [**JobCommandDto**](JobCommandDto.md)| | **jobCommandDto** | [**JobCommandDto**](JobCommandDto.md)| |
### Return type ### Return type

View File

@ -57,16 +57,16 @@ class JobApi {
return null; return null;
} }
/// Performs an HTTP 'PUT /jobs/{jobId}' operation and returns the [Response]. /// Performs an HTTP 'PUT /jobs/{id}' operation and returns the [Response].
/// Parameters: /// Parameters:
/// ///
/// * [JobName] jobId (required): /// * [JobName] id (required):
/// ///
/// * [JobCommandDto] jobCommandDto (required): /// * [JobCommandDto] jobCommandDto (required):
Future<Response> sendJobCommandWithHttpInfo(JobName jobId, JobCommandDto jobCommandDto,) async { Future<Response> sendJobCommandWithHttpInfo(JobName id, JobCommandDto jobCommandDto,) async {
// ignore: prefer_const_declarations // ignore: prefer_const_declarations
final path = r'/jobs/{jobId}' final path = r'/jobs/{id}'
.replaceAll('{jobId}', jobId.toString()); .replaceAll('{id}', id.toString());
// ignore: prefer_final_locals // ignore: prefer_final_locals
Object? postBody = jobCommandDto; Object? postBody = jobCommandDto;
@ -91,11 +91,11 @@ class JobApi {
/// Parameters: /// Parameters:
/// ///
/// * [JobName] jobId (required): /// * [JobName] id (required):
/// ///
/// * [JobCommandDto] jobCommandDto (required): /// * [JobCommandDto] jobCommandDto (required):
Future<JobStatusDto?> sendJobCommand(JobName jobId, JobCommandDto jobCommandDto,) async { Future<JobStatusDto?> sendJobCommand(JobName id, JobCommandDto jobCommandDto,) async {
final response = await sendJobCommandWithHttpInfo(jobId, jobCommandDto,); final response = await sendJobCommandWithHttpInfo(id, jobCommandDto,);
if (response.statusCode >= HttpStatus.badRequest) { if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response)); throw ApiException(response.statusCode, await _decodeBodyBytes(response));
} }

View File

@ -22,7 +22,7 @@ void main() {
// TODO // TODO
}); });
//Future<JobStatusDto> sendJobCommand(JobName jobId, JobCommandDto jobCommandDto) async //Future<JobStatusDto> sendJobCommand(JobName id, JobCommandDto jobCommandDto) async
test('test sendJobCommand', () async { test('test sendJobCommand', () async {
// TODO // TODO
}); });

View File

@ -2387,12 +2387,12 @@
] ]
} }
}, },
"/jobs/{jobId}": { "/jobs/{id}": {
"put": { "put": {
"operationId": "sendJobCommand", "operationId": "sendJobCommand",
"parameters": [ "parameters": [
{ {
"name": "jobId", "name": "id",
"required": true, "required": true,
"in": "path", "in": "path",
"schema": { "schema": {

View File

@ -6,5 +6,5 @@ export class JobIdDto {
@IsNotEmpty() @IsNotEmpty()
@IsEnum(QueueName) @IsEnum(QueueName)
@ApiProperty({ type: String, enum: QueueName, enumName: 'JobName' }) @ApiProperty({ type: String, enum: QueueName, enumName: 'JobName' })
jobId!: QueueName; id!: QueueName;
} }

View File

@ -23,22 +23,28 @@ export class JobService {
this.configCore = new SystemConfigCore(configRepository); this.configCore = new SystemConfigCore(configRepository);
} }
handleCommand(queueName: QueueName, dto: JobCommandDto): Promise<void> { async handleCommand(queueName: QueueName, dto: JobCommandDto): Promise<JobStatusDto> {
this.logger.debug(`Handling command: queue=${queueName},force=${dto.force}`); this.logger.debug(`Handling command: queue=${queueName},force=${dto.force}`);
switch (dto.command) { switch (dto.command) {
case JobCommand.START: case JobCommand.START:
return this.start(queueName, dto); await this.start(queueName, dto);
break;
case JobCommand.PAUSE: case JobCommand.PAUSE:
return this.jobRepository.pause(queueName); await this.jobRepository.pause(queueName);
break;
case JobCommand.RESUME: case JobCommand.RESUME:
return this.jobRepository.resume(queueName); await this.jobRepository.resume(queueName);
break;
case JobCommand.EMPTY: case JobCommand.EMPTY:
return this.jobRepository.empty(queueName); await this.jobRepository.empty(queueName);
break;
} }
return this.getJobStatus(queueName);
} }
async getJobStatus(queueName: QueueName): Promise<JobStatusDto> { async getJobStatus(queueName: QueueName): Promise<JobStatusDto> {

View File

@ -14,7 +14,7 @@ import { MemoryLaneResponseDto } from '@app/domain/asset/response-dto/memory-lan
export class AssetController { export class AssetController {
constructor(private service: AssetService) {} constructor(private service: AssetService) {}
@Get('/map-marker') @Get('map-marker')
getMapMarkers(@GetAuthUser() authUser: AuthUserDto, @Query() options: MapMarkerDto): Promise<MapMarkerResponseDto[]> { getMapMarkers(@GetAuthUser() authUser: AuthUserDto, @Query() options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
return this.service.getMapMarkers(authUser, options); return this.service.getMapMarkers(authUser, options);
} }

View File

@ -28,7 +28,7 @@ import { UUIDParamDto } from './dto/uuid-param.dto';
@Authenticated() @Authenticated()
@UseValidation() @UseValidation()
export class AuthController { export class AuthController {
constructor(private readonly service: AuthService) {} constructor(private service: AuthService) {}
@PublicRoute() @PublicRoute()
@Post('login') @Post('login')

View File

@ -16,9 +16,8 @@ export class JobController {
return this.service.getAllJobsStatus(); return this.service.getAllJobsStatus();
} }
@Put('/:jobId') @Put(':id')
async sendJobCommand(@Param() { jobId }: JobIdDto, @Body() dto: JobCommandDto): Promise<JobStatusDto> { sendJobCommand(@Param() { id }: JobIdDto, @Body() dto: JobCommandDto): Promise<JobStatusDto> {
await this.service.handleCommand(jobId, dto); return this.service.handleCommand(id, dto);
return this.service.getJobStatus(jobId);
} }
} }

View File

@ -8053,18 +8053,18 @@ export const JobApiAxiosParamCreator = function (configuration?: Configuration)
}, },
/** /**
* *
* @param {JobName} jobId * @param {JobName} id
* @param {JobCommandDto} jobCommandDto * @param {JobCommandDto} jobCommandDto
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
sendJobCommand: async (jobId: JobName, jobCommandDto: JobCommandDto, options: AxiosRequestConfig = {}): Promise<RequestArgs> => { sendJobCommand: async (id: JobName, jobCommandDto: JobCommandDto, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'jobId' is not null or undefined // verify required parameter 'id' is not null or undefined
assertParamExists('sendJobCommand', 'jobId', jobId) assertParamExists('sendJobCommand', 'id', id)
// verify required parameter 'jobCommandDto' is not null or undefined // verify required parameter 'jobCommandDto' is not null or undefined
assertParamExists('sendJobCommand', 'jobCommandDto', jobCommandDto) assertParamExists('sendJobCommand', 'jobCommandDto', jobCommandDto)
const localVarPath = `/jobs/{jobId}` const localVarPath = `/jobs/{id}`
.replace(`{${"jobId"}}`, encodeURIComponent(String(jobId))); .replace(`{${"id"}}`, encodeURIComponent(String(id)));
// use dummy base URL string because the URL constructor only accepts absolute URLs. // use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions; let baseOptions;
@ -8120,13 +8120,13 @@ export const JobApiFp = function(configuration?: Configuration) {
}, },
/** /**
* *
* @param {JobName} jobId * @param {JobName} id
* @param {JobCommandDto} jobCommandDto * @param {JobCommandDto} jobCommandDto
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
async sendJobCommand(jobId: JobName, jobCommandDto: JobCommandDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<JobStatusDto>> { async sendJobCommand(id: JobName, jobCommandDto: JobCommandDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<JobStatusDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.sendJobCommand(jobId, jobCommandDto, options); const localVarAxiosArgs = await localVarAxiosParamCreator.sendJobCommand(id, jobCommandDto, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
}, },
} }
@ -8149,13 +8149,13 @@ export const JobApiFactory = function (configuration?: Configuration, basePath?:
}, },
/** /**
* *
* @param {JobName} jobId * @param {JobName} id
* @param {JobCommandDto} jobCommandDto * @param {JobCommandDto} jobCommandDto
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
sendJobCommand(jobId: JobName, jobCommandDto: JobCommandDto, options?: any): AxiosPromise<JobStatusDto> { sendJobCommand(id: JobName, jobCommandDto: JobCommandDto, options?: any): AxiosPromise<JobStatusDto> {
return localVarFp.sendJobCommand(jobId, jobCommandDto, options).then((request) => request(axios, basePath)); return localVarFp.sendJobCommand(id, jobCommandDto, options).then((request) => request(axios, basePath));
}, },
}; };
}; };
@ -8171,7 +8171,7 @@ export interface JobApiSendJobCommandRequest {
* @type {JobName} * @type {JobName}
* @memberof JobApiSendJobCommand * @memberof JobApiSendJobCommand
*/ */
readonly jobId: JobName readonly id: JobName
/** /**
* *
@ -8206,7 +8206,7 @@ export class JobApi extends BaseAPI {
* @memberof JobApi * @memberof JobApi
*/ */
public sendJobCommand(requestParameters: JobApiSendJobCommandRequest, options?: AxiosRequestConfig) { public sendJobCommand(requestParameters: JobApiSendJobCommandRequest, options?: AxiosRequestConfig) {
return JobApiFp(this.configuration).sendJobCommand(requestParameters.jobId, requestParameters.jobCommandDto, options).then((request) => request(this.axios, this.basePath)); return JobApiFp(this.configuration).sendJobCommand(requestParameters.id, requestParameters.jobCommandDto, options).then((request) => request(this.axios, this.basePath));
} }
} }

View File

@ -105,7 +105,7 @@
const title = jobDetails[jobId]?.title; const title = jobDetails[jobId]?.title;
try { try {
const { data } = await api.jobApi.sendJobCommand({ jobId, jobCommandDto: jobCommand }); const { data } = await api.jobApi.sendJobCommand({ id: jobId, jobCommandDto: jobCommand });
jobs[jobId] = data; jobs[jobId] = data;
switch (jobCommand.command) { switch (jobCommand.command) {