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* | [**validateAccessToken**](doc//AuthenticationApi.md#validateaccesstoken) | **POST** /auth/validateToken |
*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* | [**generateConfig**](doc//OAuthApi.md#generateconfig) | **POST** /oauth/config |
*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
------------- | ------------- | -------------
[**getAllJobsStatus**](JobApi.md#getalljobsstatus) | **GET** /jobs |
[**sendJobCommand**](JobApi.md#sendjobcommand) | **PUT** /jobs/{jobId} |
[**sendJobCommand**](JobApi.md#sendjobcommand) | **PUT** /jobs/{id} |
# **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)
# **sendJobCommand**
> JobStatusDto sendJobCommand(jobId, jobCommandDto)
> JobStatusDto sendJobCommand(id, jobCommandDto)
@ -88,11 +88,11 @@ import 'package:openapi/api.dart';
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = JobApi();
final jobId = ; // JobName |
final id = ; // JobName |
final jobCommandDto = JobCommandDto(); // JobCommandDto |
try {
final result = api_instance.sendJobCommand(jobId, jobCommandDto);
final result = api_instance.sendJobCommand(id, jobCommandDto);
print(result);
} catch (e) {
print('Exception when calling JobApi->sendJobCommand: $e\n');
@ -103,7 +103,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**jobId** | [**JobName**](.md)| |
**id** | [**JobName**](.md)| |
**jobCommandDto** | [**JobCommandDto**](JobCommandDto.md)| |
### Return type

View file

@ -57,16 +57,16 @@ class JobApi {
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:
///
/// * [JobName] jobId (required):
/// * [JobName] id (required):
///
/// * [JobCommandDto] jobCommandDto (required):
Future<Response> sendJobCommandWithHttpInfo(JobName jobId, JobCommandDto jobCommandDto,) async {
Future<Response> sendJobCommandWithHttpInfo(JobName id, JobCommandDto jobCommandDto,) async {
// ignore: prefer_const_declarations
final path = r'/jobs/{jobId}'
.replaceAll('{jobId}', jobId.toString());
final path = r'/jobs/{id}'
.replaceAll('{id}', id.toString());
// ignore: prefer_final_locals
Object? postBody = jobCommandDto;
@ -91,11 +91,11 @@ class JobApi {
/// Parameters:
///
/// * [JobName] jobId (required):
/// * [JobName] id (required):
///
/// * [JobCommandDto] jobCommandDto (required):
Future<JobStatusDto?> sendJobCommand(JobName jobId, JobCommandDto jobCommandDto,) async {
final response = await sendJobCommandWithHttpInfo(jobId, jobCommandDto,);
Future<JobStatusDto?> sendJobCommand(JobName id, JobCommandDto jobCommandDto,) async {
final response = await sendJobCommandWithHttpInfo(id, jobCommandDto,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}

View file

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

View file

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

View file

@ -6,5 +6,5 @@ export class JobIdDto {
@IsNotEmpty()
@IsEnum(QueueName)
@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);
}
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}`);
switch (dto.command) {
case JobCommand.START:
return this.start(queueName, dto);
await this.start(queueName, dto);
break;
case JobCommand.PAUSE:
return this.jobRepository.pause(queueName);
await this.jobRepository.pause(queueName);
break;
case JobCommand.RESUME:
return this.jobRepository.resume(queueName);
await this.jobRepository.resume(queueName);
break;
case JobCommand.EMPTY:
return this.jobRepository.empty(queueName);
await this.jobRepository.empty(queueName);
break;
}
return this.getJobStatus(queueName);
}
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 {
constructor(private service: AssetService) {}
@Get('/map-marker')
@Get('map-marker')
getMapMarkers(@GetAuthUser() authUser: AuthUserDto, @Query() options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
return this.service.getMapMarkers(authUser, options);
}

View file

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

View file

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

View file

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