fixed up worker counts
This commit is contained in:
parent
f41622e530
commit
fa67d666dc
5 changed files with 182 additions and 28 deletions
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
import { getRandomUserAgent } from '@stock-bot/utils';
|
||||
import type { CeoHandler } from '../ceo.handler';
|
||||
|
||||
export async function processIndividualSymbol(
|
||||
this: CeoHandler,
|
||||
payload: any,
|
||||
_context: any
|
||||
): Promise<unknown> {
|
||||
const { ceoId, symbol, timestamp } = payload;
|
||||
const proxy = this.proxy?.getProxy();
|
||||
if (!proxy) {
|
||||
this.logger.warn('No proxy available for processing individual CEO symbol');
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.debug(`Processing individual CEO symbol for ${symbol}`, {
|
||||
ceoId,
|
||||
timestamp,
|
||||
});
|
||||
try {
|
||||
// Update Shorts
|
||||
const response = await this.http.get(
|
||||
`https://api.ceo.ca/api/short_positions/one?symbol=${symbol}`,
|
||||
{
|
||||
proxy: proxy,
|
||||
headers: {
|
||||
'User-Agent': getRandomUserAgent(),
|
||||
},
|
||||
}
|
||||
);
|
||||
let shortCount = 0;
|
||||
|
||||
if (response.ok) {
|
||||
const shortData = await response.json();
|
||||
if (shortData && shortData.positions) {
|
||||
shortCount = shortData.positions.length;
|
||||
await this.mongodb.batchUpsert('ceoShorts', shortData.positions, ['id']);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.info(
|
||||
`Successfully processed CEO symbol ${symbol} shorts and found ${shortCount} positions`,
|
||||
);
|
||||
|
||||
return { ceoId, shortCount, timestamp };
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to process individual symbol ${symbol}`, {
|
||||
error,
|
||||
ceoId,
|
||||
timestamp,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ export async function processIndividualSymbol(
|
|||
const spielCount = data.spiels.length;
|
||||
if (spielCount === 0) {
|
||||
this.logger.warn(`No spiels found for ceoId ${ceoId}`);
|
||||
await this.mongodb.updateMany('ceoChannels', { ceoId }, { $set: { lastSpielTime: timestamp, finished: true } });
|
||||
return null; // No data to process
|
||||
}
|
||||
const latestSpielTime = data.spiels[0]?.timestamp;
|
||||
|
|
@ -76,35 +77,18 @@ export async function processIndividualSymbol(
|
|||
}));
|
||||
|
||||
await this.mongodb.batchUpsert('ceoPosts', posts, ['spielId']);
|
||||
await this.mongodb.updateMany('ceoChannels', { ceoId }, { $set: { lastSpielTime: latestSpielTime } });
|
||||
this.logger.info(`Fetched ${spielCount} spiels for ceoId ${ceoId}`);
|
||||
|
||||
// Update Shorts
|
||||
const shortRes = await this.http.get(
|
||||
`https://api.ceo.ca/api/short_positions/one?symbol=${symbol}`,
|
||||
await this.scheduleOperation(
|
||||
'process-individual-symbol',
|
||||
{
|
||||
proxy: proxy,
|
||||
headers: {
|
||||
'User-Agent': getRandomUserAgent(),
|
||||
},
|
||||
}
|
||||
ceoId: ceoId,
|
||||
timestamp: latestSpielTime,
|
||||
},
|
||||
{ priority: 0 }
|
||||
);
|
||||
|
||||
if (shortRes.ok) {
|
||||
const shortData = await shortRes.json();
|
||||
if (shortData && shortData.positions) {
|
||||
await this.mongodb.batchUpsert('ceoShorts', shortData.positions, ['id']);
|
||||
}
|
||||
|
||||
await this.scheduleOperation(
|
||||
'process-individual-symbol',
|
||||
{
|
||||
ceoId: ceoId,
|
||||
timestamp: latestSpielTime,
|
||||
},
|
||||
{ priority: 0 }
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.info(
|
||||
`Successfully processed channel ${ceoId} and added channel ${ceoId} at timestamp ${latestSpielTime}`
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue