work on ceo

This commit is contained in:
Boki 2025-06-24 18:09:32 -04:00
parent c8dcd697c9
commit b25222778e
18 changed files with 391 additions and 110 deletions

View file

@ -76,7 +76,7 @@
"delay": 1000
},
"removeOnComplete": 100,
"removeOnFail": 50
"removeOnFail": 100
}
},
"http": {

View file

@ -32,7 +32,7 @@
"defaultJobOptions": {
"attempts": 1,
"removeOnComplete": 100,
"removeOnFail": 50
"removeOnFail": 100
}
},
"http": {

View file

@ -55,7 +55,7 @@ export const queueConfigSchema = z.object({
})
.default({}),
removeOnComplete: z.number().default(100),
removeOnFail: z.number().default(50),
removeOnFail: z.number().default(100),
timeout: z.number().optional(),
})
.default({}),

View file

@ -32,7 +32,7 @@ export const queueConfigSchema = z.object({
})
.default({}),
removeOnComplete: z.number().default(100),
removeOnFail: z.number().default(50),
removeOnFail: z.number().default(100),
timeout: z.number().optional(),
})
.optional()

View file

@ -1,7 +1,7 @@
import { asClass, asFunction, createContainer, InjectionMode, type AwilixContainer } from 'awilix';
import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
import { toUnifiedConfig } from '@stock-bot/config';
import { HandlerRegistry } from '@stock-bot/handler-registry';
import { asClass, asFunction, createContainer, InjectionMode, type AwilixContainer } from 'awilix';
import { appConfigSchema, type AppConfig } from '../config/schemas';
import {
registerApplicationServices,
@ -133,7 +133,7 @@ export class ServiceContainerBuilder {
attempts: 3,
backoff: { type: 'exponential' as const, delay: 1000 },
removeOnComplete: 100,
removeOnFail: 50,
removeOnFail: 100,
},
}
: undefined,

View file

@ -88,8 +88,8 @@ async function processDirect<T>(
delay: index * delayPerItem,
priority: options.priority || undefined,
attempts: options.retries || 3,
removeOnComplete: options.removeOnComplete || 10,
removeOnFail: options.removeOnFail || 5,
removeOnComplete: options.removeOnComplete || 100,
removeOnFail: options.removeOnFail || 100,
},
}));
@ -151,8 +151,8 @@ async function processBatched<T>(
delay: batchIndex * delayPerBatch,
priority: options.priority || undefined,
attempts: options.retries || 3,
removeOnComplete: options.removeOnComplete || 10,
removeOnFail: options.removeOnFail || 5,
removeOnComplete: options.removeOnComplete || 100,
removeOnFail: options.removeOnFail || 100,
},
};
})

View file

@ -85,7 +85,7 @@ export class DeadLetterQueueHandler {
await this.dlq.add('failed-job', dlqData, {
removeOnComplete: 100,
removeOnFail: 50,
removeOnFail: 100,
});
this.logger.error('Job moved to DLQ', {

View file

@ -63,8 +63,8 @@ export class Queue {
this.bullQueue = new BullQueue(queueName, {
connection,
defaultJobOptions: {
removeOnComplete: 10,
removeOnFail: 5,
removeOnComplete: 100,
removeOnFail: 100,
attempts: 3,
backoff: {
type: 'exponential',

View file

@ -311,7 +311,7 @@ describe('Batch Processor', () => {
priority: 5,
retries: 10,
removeOnComplete: 100,
removeOnFail: 50,
removeOnFail: 100,
});
// Check all states including job ID "1" specifically (as it often doesn't show up in state queries)
@ -337,7 +337,7 @@ describe('Batch Processor', () => {
expect(job.opts.priority).toBe(5);
expect(job.opts.attempts).toBe(10);
expect(job.opts.removeOnComplete).toBe(100);
expect(job.opts.removeOnFail).toBe(50);
expect(job.opts.removeOnFail).toBe(100);
});
});

View file

@ -363,6 +363,254 @@ export class MongoDBClient {
return { ...docWithTimestamps, _id: result.insertedId } as T;
}
/**
* Insert multiple documents
*/
async insertMany<T = any>(
collectionName: string,
documents: T[],
options?: any,
dbName?: string
): Promise<any> {
const collection = this.getCollection(collectionName, dbName);
const now = new Date();
const docsWithTimestamps = documents.map(doc => ({
...doc,
created_at: (doc as any).created_at || now,
updated_at: now,
}));
const result = await collection.insertMany(docsWithTimestamps as any, options);
return {
insertedCount: result.insertedCount,
insertedIds: result.insertedIds,
};
}
/**
* Find multiple documents
*/
async find<T = any>(
collectionName: string,
filter: any = {},
options?: any,
dbName?: string
): Promise<T[]> {
const collection = this.getCollection(collectionName, dbName);
const cursor = collection.find(filter, options);
return await cursor.toArray() as T[];
}
/**
* Find a single document
*/
async findOne<T = any>(
collectionName: string,
filter: any,
options?: any,
dbName?: string
): Promise<T | null> {
const collection = this.getCollection(collectionName, dbName);
const result = await collection.findOne(filter, options);
return result as T | null;
}
/**
* Update a single document
*/
async updateOne(
collectionName: string,
filter: any,
update: any,
options?: any,
dbName?: string
): Promise<any> {
const collection = this.getCollection(collectionName, dbName);
// Add updated_at timestamp
if (update.$set) {
update.$set.updated_at = new Date();
} else if (!update.$setOnInsert && !update.$unset && !update.$inc) {
update = { $set: { ...update, updated_at: new Date() } };
}
const result = await collection.updateOne(filter, update, options);
return {
matchedCount: result.matchedCount,
modifiedCount: result.modifiedCount,
upsertedCount: result.upsertedCount,
upsertedId: result.upsertedId,
};
}
/**
* Update multiple documents
*/
async updateMany(
collectionName: string,
filter: any,
update: any,
options?: any,
dbName?: string
): Promise<any> {
const collection = this.getCollection(collectionName, dbName);
// Add updated_at timestamp
if (update.$set) {
update.$set.updated_at = new Date();
} else if (!update.$setOnInsert && !update.$unset && !update.$inc) {
update = { $set: { ...update, updated_at: new Date() } };
}
const result = await collection.updateMany(filter, update, options);
return {
matchedCount: result.matchedCount,
modifiedCount: result.modifiedCount,
upsertedCount: result.upsertedCount,
upsertedId: result.upsertedId,
};
}
/**
* Delete a single document
*/
async deleteOne(
collectionName: string,
filter: any,
options?: any,
dbName?: string
): Promise<any> {
const collection = this.getCollection(collectionName, dbName);
const result = await collection.deleteOne(filter, options);
return {
deletedCount: result.deletedCount,
};
}
/**
* Delete multiple documents
*/
async deleteMany(
collectionName: string,
filter: any,
options?: any,
dbName?: string
): Promise<any> {
const collection = this.getCollection(collectionName, dbName);
const result = await collection.deleteMany(filter, options);
return {
deletedCount: result.deletedCount,
};
}
/**
* Count documents matching a filter
*/
async countDocuments(
collectionName: string,
filter: any = {},
options?: any,
dbName?: string
): Promise<number> {
const collection = this.getCollection(collectionName, dbName);
return await collection.countDocuments(filter, options);
}
/**
* Perform aggregation operations
*/
async aggregate<T = any>(
collectionName: string,
pipeline: any[],
options?: any,
dbName?: string
): Promise<T[]> {
const collection = this.getCollection(collectionName, dbName);
const cursor = collection.aggregate(pipeline, options);
return await cursor.toArray() as T[];
}
/**
* Create an index
*/
async createIndex(
collectionName: string,
indexSpec: any,
options?: any,
dbName?: string
): Promise<string> {
const collection = this.getCollection(collectionName, dbName);
return await collection.createIndex(indexSpec, options);
}
/**
* Drop an index
*/
async dropIndex(
collectionName: string,
indexName: string,
options?: any,
dbName?: string
): Promise<void> {
const collection = this.getCollection(collectionName, dbName);
await collection.dropIndex(indexName, options);
}
/**
* List all indexes on a collection
*/
async listIndexes(
collectionName: string,
dbName?: string
): Promise<any[]> {
const collection = this.getCollection(collectionName, dbName);
const cursor = collection.listIndexes();
return await cursor.toArray();
}
/**
* Get a database instance (interface compatibility)
*/
getDb(dbName?: string): Db {
return this.getDatabase(dbName);
}
/**
* Create a new collection
*/
async createCollection(
collectionName: string,
options?: any,
dbName?: string
): Promise<void> {
const db = this.getDatabase(dbName);
await db.createCollection(collectionName, options);
}
/**
* Drop a collection
*/
async dropCollection(
collectionName: string,
dbName?: string
): Promise<void> {
const db = this.getDatabase(dbName);
await db.dropCollection(collectionName);
}
/**
* List all collections in a database
*/
async listCollections(
filter: any = {},
dbName?: string
): Promise<any[]> {
const db = this.getDatabase(dbName);
const collections = await db.listCollections(filter).toArray();
return collections;
}
/**
* Check if client is connected
*/