huge refactor to remove depenencie hell and add typesafe container
This commit is contained in:
parent
28b9822d55
commit
843a7b9b9b
148 changed files with 3603 additions and 2378 deletions
|
|
@ -12,28 +12,29 @@ export function usePipeline() {
|
|||
const [error, setError] = useState<string | null>(null);
|
||||
const [lastJobResult, setLastJobResult] = useState<PipelineJobResult | null>(null);
|
||||
|
||||
const executeOperation = useCallback(async (
|
||||
operation: () => Promise<PipelineJobResult>
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const result = await operation();
|
||||
setLastJobResult(result);
|
||||
if (!result.success) {
|
||||
setError(result.error || 'Operation failed');
|
||||
const executeOperation = useCallback(
|
||||
async (operation: () => Promise<PipelineJobResult>): Promise<boolean> => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const result = await operation();
|
||||
setLastJobResult(result);
|
||||
if (!result.success) {
|
||||
setError(result.error || 'Operation failed');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
setError(errorMessage);
|
||||
setLastJobResult({ success: false, error: errorMessage });
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
setError(errorMessage);
|
||||
setLastJobResult({ success: false, error: errorMessage });
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// Symbol sync operations
|
||||
const syncQMSymbols = useCallback(
|
||||
|
|
@ -53,7 +54,7 @@ export function usePipeline() {
|
|||
);
|
||||
|
||||
const syncAllExchanges = useCallback(
|
||||
(clearFirst: boolean = false) =>
|
||||
(clearFirst: boolean = false) =>
|
||||
executeOperation(() => pipelineApi.syncAllExchanges(clearFirst)),
|
||||
[executeOperation]
|
||||
);
|
||||
|
|
@ -71,7 +72,7 @@ export function usePipeline() {
|
|||
|
||||
// Maintenance operations
|
||||
const clearPostgreSQLData = useCallback(
|
||||
(dataType: DataClearType = 'all') =>
|
||||
(dataType: DataClearType = 'all') =>
|
||||
executeOperation(() => pipelineApi.clearPostgreSQLData(dataType)),
|
||||
[executeOperation]
|
||||
);
|
||||
|
|
@ -122,7 +123,8 @@ export function usePipeline() {
|
|||
setError(result.error || 'Failed to get provider mapping stats');
|
||||
return null;
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Failed to get provider mapping stats';
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : 'Failed to get provider mapping stats';
|
||||
setError(errorMessage);
|
||||
return null;
|
||||
} finally {
|
||||
|
|
@ -156,4 +158,4 @@ export function usePipeline() {
|
|||
getExchangeStats,
|
||||
getProviderMappingStats,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export { PipelinePage } from './PipelinePage';
|
||||
export * from './hooks/usePipeline';
|
||||
export * from './types';
|
||||
export * from './types';
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
import type {
|
||||
DataClearType,
|
||||
PipelineJobResult,
|
||||
PipelineStatsResult,
|
||||
} from '../types';
|
||||
import type { DataClearType, PipelineJobResult, PipelineStatsResult } from '../types';
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:2003';
|
||||
|
||||
class PipelineApiService {
|
||||
private async request<T = unknown>(
|
||||
endpoint: string,
|
||||
options?: RequestInit
|
||||
): Promise<T> {
|
||||
private async request<T = unknown>(endpoint: string, options?: RequestInit): Promise<T> {
|
||||
const url = `${API_BASE_URL}/pipeline${endpoint}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
|
|
@ -79,4 +72,4 @@ class PipelineApiService {
|
|||
}
|
||||
|
||||
// Export singleton instance
|
||||
export const pipelineApi = new PipelineApiService();
|
||||
export const pipelineApi = new PipelineApiService();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ export interface ProviderMappingStats {
|
|||
coveragePercentage: number;
|
||||
}
|
||||
|
||||
|
||||
export type DataClearType = 'exchanges' | 'provider_mappings' | 'all';
|
||||
|
||||
export interface PipelineOperation {
|
||||
|
|
@ -44,4 +43,4 @@ export interface PipelineOperation {
|
|||
category: 'sync' | 'stats' | 'maintenance';
|
||||
dangerous?: boolean;
|
||||
params?: Record<string, unknown>;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue