adding data-services
This commit is contained in:
parent
e3bfd05b90
commit
405b818c86
139 changed files with 55943 additions and 416 deletions
|
|
@ -0,0 +1,220 @@
|
|||
import { Context } from 'hono';
|
||||
import { FeatureComputationService } from '../services/FeatureComputationService';
|
||||
import { Logger } from '@stock-bot/utils';
|
||||
import {
|
||||
ComputationJob,
|
||||
CreateComputationJobRequest,
|
||||
UpdateComputationJobRequest
|
||||
} from '../types/FeatureStore';
|
||||
|
||||
export class ComputationController {
|
||||
constructor(
|
||||
private computationService: FeatureComputationService,
|
||||
private logger: Logger
|
||||
) {}
|
||||
|
||||
async createComputationJob(c: Context) {
|
||||
try {
|
||||
const request: CreateComputationJobRequest = await c.req.json();
|
||||
|
||||
const job = await this.computationService.createComputationJob(request);
|
||||
|
||||
this.logger.info('Computation job created', { jobId: job.id });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: job
|
||||
}, 201);
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to create computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async getComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
|
||||
const job = await this.computationService.getComputationJob(jobId);
|
||||
|
||||
if (!job) {
|
||||
return c.json({
|
||||
success: false,
|
||||
error: 'Computation job not found'
|
||||
}, 404);
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: job
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to get computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async updateComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
const request: UpdateComputationJobRequest = await c.req.json();
|
||||
|
||||
const job = await this.computationService.updateComputationJob(jobId, request);
|
||||
|
||||
if (!job) {
|
||||
return c.json({
|
||||
success: false,
|
||||
error: 'Computation job not found'
|
||||
}, 404);
|
||||
}
|
||||
|
||||
this.logger.info('Computation job updated', { jobId });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: job
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to update computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
|
||||
await this.computationService.deleteComputationJob(jobId);
|
||||
|
||||
this.logger.info('Computation job deleted', { jobId });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: 'Computation job deleted successfully'
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to delete computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async listComputationJobs(c: Context) {
|
||||
try {
|
||||
const featureGroupId = c.req.query('featureGroupId');
|
||||
const status = c.req.query('status');
|
||||
|
||||
const jobs = await this.computationService.listComputationJobs({
|
||||
featureGroupId,
|
||||
status: status as any
|
||||
});
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: jobs
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to list computation jobs', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async executeComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
|
||||
const result = await this.computationService.executeComputationJob(jobId);
|
||||
|
||||
this.logger.info('Computation job executed', { jobId, result });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: result
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to execute computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async scheduleComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
const { schedule } = await c.req.json();
|
||||
|
||||
await this.computationService.scheduleComputationJob(jobId, schedule);
|
||||
|
||||
this.logger.info('Computation job scheduled', { jobId, schedule });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: 'Computation job scheduled successfully'
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to schedule computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async unscheduleComputationJob(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
|
||||
await this.computationService.unscheduleComputationJob(jobId);
|
||||
|
||||
this.logger.info('Computation job unscheduled', { jobId });
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: 'Computation job unscheduled successfully'
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to unschedule computation job', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async getComputationJobHistory(c: Context) {
|
||||
try {
|
||||
const jobId = c.req.param('id');
|
||||
const limit = parseInt(c.req.query('limit') || '10');
|
||||
const offset = parseInt(c.req.query('offset') || '0');
|
||||
|
||||
const history = await this.computationService.getComputationJobHistory(jobId, limit, offset);
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: history
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to get computation job history', { error });
|
||||
return c.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue