Minor changes

This commit is contained in:
Apher 2026-07-07 00:35:58 +00:00
parent aa00d45eef
commit c3f00ac699

View File

@ -23,7 +23,7 @@ const handleIntent = async (streamKey, intent) => {
console.log("TODO: Handle Intents", intent); console.log("TODO: Handle Intents", intent);
} }
const processor = async (group, consumer, streamKey) => { async function processor(group, consumer, streamKey) {
await redis.client.connect().catch(console.error); await redis.client.connect().catch(console.error);
while (true) { while (true) {
@ -38,16 +38,18 @@ const processor = async (group, consumer, streamKey) => {
for (const stream of res) { for (const stream of res) {
for (const msg of stream.messages) { for (const msg of stream.messages) {
try {
console.log(`[${consumer}] Processing:`, msg); console.log(`[${consumer}] Processing:`, msg);
await handleIntent("commands", msg); await handleIntent("commands", msg);
await redis.client.xAck(streamKey, group, msg.id); await redis.client.xAck(streamKey, group, msg.id);
} catch (err) {
console.error("Failed to process message:", err);
}
} }
} }
} }
await redis.client.disconnect();
} }
const main = async () => { const main = async () => {
@ -55,12 +57,13 @@ const main = async () => {
const doForce = config.FORCE_DB_SYNC === "true" && config.NODE_ENV !== "production"; const doForce = config.FORCE_DB_SYNC === "true" && config.NODE_ENV !== "production";
await sequelize.authenticate(); await sequelize.authenticate();
await sequelize.sync({force: doForce}); await sequelize.sync({force: doForce});
if (doForce) console.info("Database dropped and resynced (force=true)."); if (doForce) console.info("Database dropped and resynced (force=true).");
await redis.ensureGroup("transcripts", 'nlp'); await redis.ensureGroup("transcripts", 'nlp');
await redis.ensureGroup("commands", 'nlp'); await redis.ensureGroup("commands", 'nlp');
processor('nlp', `${config.DEVICE_ID}`, "transcripts"); processor('nlp', `${config.DEVICE_ID}`, "transcripts").catch(console.error);
} }
main().catch(console.error); main().catch(console.error);