refactoring handlers
This commit is contained in:
parent
59ab0940ae
commit
ab0b7a5385
12 changed files with 1098 additions and 25 deletions
|
|
@ -5,11 +5,11 @@ import { ProxyInfo } from '@stock-bot/http';
|
|||
import { getLogger } from '@stock-bot/logger';
|
||||
import { handlerRegistry, createJobHandler, type HandlerConfigWithSchedule } from '@stock-bot/queue';
|
||||
|
||||
const logger = getLogger('proxy-provider');
|
||||
const handlerLogger = getLogger('proxy-handler');
|
||||
|
||||
// Initialize and register the Proxy provider
|
||||
export function initializeProxyProvider() {
|
||||
logger.debug('Registering proxy provider with scheduled jobs...');
|
||||
handlerLogger.debug('Registering proxy provider with scheduled jobs...');
|
||||
|
||||
const proxyProviderConfig: HandlerConfigWithSchedule = {
|
||||
name: 'proxy',
|
||||
|
|
@ -17,16 +17,16 @@ export function initializeProxyProvider() {
|
|||
operations: {
|
||||
'fetch-from-sources': createJobHandler(async () => {
|
||||
// Fetch proxies from all configured sources
|
||||
logger.info('Processing fetch proxies from sources request');
|
||||
handlerLogger.info('Processing fetch proxies from sources request');
|
||||
const { fetchProxiesFromSources } = await import('./proxy.operations');
|
||||
const { processItems } = await import('@stock-bot/queue');
|
||||
|
||||
// Fetch all proxies from sources
|
||||
const proxies = await fetchProxiesFromSources();
|
||||
logger.info('Fetched proxies from sources', { count: proxies.length });
|
||||
handlerLogger.info('Fetched proxies from sources', { count: proxies.length });
|
||||
|
||||
if (proxies.length === 0) {
|
||||
logger.warn('No proxies fetched from sources');
|
||||
handlerLogger.warn('No proxies fetched from sources');
|
||||
return { processed: 0, successful: 0 };
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ export function initializeProxyProvider() {
|
|||
removeOnFail: 3,
|
||||
});
|
||||
|
||||
logger.info('Batch proxy validation completed', {
|
||||
handlerLogger.info('Batch proxy validation completed', {
|
||||
totalProxies: proxies.length,
|
||||
jobsCreated: batchResult.jobsCreated,
|
||||
mode: batchResult.mode,
|
||||
|
|
@ -62,7 +62,7 @@ export function initializeProxyProvider() {
|
|||
|
||||
'check-proxy': createJobHandler(async (payload: ProxyInfo) => {
|
||||
// payload is now the raw proxy info object
|
||||
logger.debug('Processing proxy check request', {
|
||||
handlerLogger.debug('Processing proxy check request', {
|
||||
proxy: `${payload.host}:${payload.port}`,
|
||||
});
|
||||
const { checkProxy } = await import('./proxy.operations');
|
||||
|
|
@ -82,5 +82,5 @@ export function initializeProxyProvider() {
|
|||
};
|
||||
|
||||
handlerRegistry.registerWithSchedule(proxyProviderConfig);
|
||||
logger.debug('Proxy provider registered successfully with scheduled jobs');
|
||||
handlerLogger.debug('Proxy provider registered successfully with scheduled jobs');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue