mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-19 10:49:07 +00:00
FEAT: update job deletion logic to mark tables as deleted and adjust API endpoints accordingly
This commit is contained in:
@@ -965,42 +965,45 @@ export class PlatformApiController {
|
||||
);
|
||||
}
|
||||
|
||||
@Delete('inputs/:inputId/jobs/:jobId')
|
||||
@ApiOperation({ summary: 'Delete a job and mark its table as deleted via in-factory' })
|
||||
@Delete('inputs/:inputId/tables/:tableName')
|
||||
@ApiOperation({ summary: 'Mark a table as deleted and delete its associated job via platform-api' })
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE)
|
||||
async deleteJob(
|
||||
async deleteTable(
|
||||
@Param('inputId') inputId: string,
|
||||
@Param('jobId') jobId: string,
|
||||
@Param('tableName') tableName: string,
|
||||
@Query('pipelineId') pipelineId: string,
|
||||
@User() user: RequestUser,
|
||||
) {
|
||||
const normalizedJobId = this.normalizeJobId(jobId);
|
||||
|
||||
const jobDetails = await this.platformApiService.proxy('GET', `/jobs/${normalizedJobId}`, user);
|
||||
const tableName: string | undefined = jobDetails?.source_config?.table_name;
|
||||
|
||||
if (!tableName) {
|
||||
throw new NotFoundException(`Job ${jobId} not found or has no associated table`);
|
||||
}
|
||||
|
||||
const info = {
|
||||
customer_id: user.customer_id,
|
||||
customer: user.customer_name,
|
||||
user_id: user.user_id,
|
||||
};
|
||||
|
||||
this.logger.info('deleteTable: marking table as deleted', { inputId, tableName });
|
||||
const updatedInput: any = await this.inputsService.markTableDeleted({ input_id: inputId, table_name: tableName, info });
|
||||
this.logger.info('deleteTable: table marked as deleted', { inputId, tableName });
|
||||
|
||||
try {
|
||||
await this.platformApiService.proxy('DELETE', `/jobs/${normalizedJobId}`, user);
|
||||
const normalizedPipelineId = this.normalizeJobId(pipelineId);
|
||||
this.logger.info('deleteTable: fetching pipeline from platform-api', { pipelineId, normalizedPipelineId });
|
||||
const platformPipeline = await this.platformApiService.proxy('GET', `/pipeline/${normalizedPipelineId}`, user);
|
||||
this.logger.info('deleteTable: pipeline fetched', { jobCount: platformPipeline?.jobs?.length });
|
||||
|
||||
const updatedTable = updatedInput.tables?.find((t: any) => t.name === tableName);
|
||||
return updatedTable ?? { name: tableName, is_deleted: true };
|
||||
const job = platformPipeline?.jobs?.find((j: any) => j.input?.table_name === tableName);
|
||||
if (!job) throw new NotFoundException(`Job for table '${tableName}' not found in pipeline`);
|
||||
|
||||
this.logger.info('deleteTable: deleting job from platform-api', { jobId: job.job_id });
|
||||
await this.platformApiService.proxy('DELETE', `/jobs/${job.job_id}`, user);
|
||||
this.logger.info('deleteTable: job deleted', { jobId: job.job_id });
|
||||
|
||||
return { name: tableName, is_deleted: updatedInput.is_deleted ?? true, deleted_at: updatedInput.deleted_at };
|
||||
} catch (error) {
|
||||
this.logger.error('deleteJob: platform-api delete failed, attempting rollback', { jobId, tableName, error: error.message });
|
||||
this.logger.error('deleteTable: platform-api delete failed, attempting rollback', { tableName, error: error.message });
|
||||
try {
|
||||
await this.inputsService.unmarkTableDeleted({ input_id: inputId, table_name: tableName, info });
|
||||
} catch (rollbackError) {
|
||||
this.logger.error('deleteJob: rollback failed', { jobId, tableName, error: rollbackError.message });
|
||||
this.logger.error('deleteTable: rollback failed', { tableName, error: rollbackError.message });
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user