Spaces:
Running
Running
Download apps/api/dist/queue/outreach.processor.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 6.41 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/queue/outreach.processor.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/queue/outreach.processor.js
-
curl -L -o outreach.processor.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/queue/outreach.processor.js
6.41 kB
| ; | |
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | |
| if (k2 === undefined) k2 = k; | |
| var desc = Object.getOwnPropertyDescriptor(m, k); | |
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | |
| desc = { enumerable: true, get: function() { return m[k]; } }; | |
| } | |
| Object.defineProperty(o, k2, desc); | |
| }) : (function(o, m, k, k2) { | |
| if (k2 === undefined) k2 = k; | |
| o[k2] = m[k]; | |
| })); | |
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | |
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | |
| }) : function(o, v) { | |
| o["default"] = v; | |
| }); | |
| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | |
| var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | |
| if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | |
| else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | |
| return c > 3 && r && Object.defineProperty(target, key, r), r; | |
| }; | |
| var __importStar = (this && this.__importStar) || (function () { | |
| var ownKeys = function(o) { | |
| ownKeys = Object.getOwnPropertyNames || function (o) { | |
| var ar = []; | |
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | |
| return ar; | |
| }; | |
| return ownKeys(o); | |
| }; | |
| return function (mod) { | |
| if (mod && mod.__esModule) return mod; | |
| var result = {}; | |
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | |
| __setModuleDefault(result, mod); | |
| return result; | |
| }; | |
| })(); | |
| var __metadata = (this && this.__metadata) || function (k, v) { | |
| if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | |
| }; | |
| var OutreachProcessor_1; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.OutreachProcessor = void 0; | |
| const bullmq_1 = require("@nestjs/bullmq"); | |
| const common_1 = require("@nestjs/common"); | |
| const config_1 = require("@nestjs/config"); | |
| const bullmq_2 = require("bullmq"); | |
| const prisma_service_1 = require("../prisma/prisma.service"); | |
| let OutreachProcessor = OutreachProcessor_1 = class OutreachProcessor extends bullmq_1.WorkerHost { | |
| prisma; | |
| configService; | |
| logger = new common_1.Logger(OutreachProcessor_1.name); | |
| resendApiKey = null; | |
| constructor(prisma, configService) { | |
| super(); | |
| this.prisma = prisma; | |
| this.configService = configService; | |
| this.resendApiKey = this.configService.get("RESEND_API_KEY") || null; | |
| } | |
| async process(job) { | |
| this.logger.log(`Processing job ${job.id} of type ${job.name}`); | |
| switch (job.name) { | |
| case "send-email": | |
| await this.handleSendEmail(job.data); | |
| break; | |
| case "schedule-message": | |
| await this.handleScheduleMessage(job.data); | |
| break; | |
| default: | |
| this.logger.warn(`Unknown job type: ${job.name}`); | |
| } | |
| } | |
| async handleSendEmail(data) { | |
| this.logger.log(`Sending email to ${data.to}: ${data.subject}`); | |
| if (!this.resendApiKey) { | |
| this.logger.warn("RESEND_API_KEY not configured - email not sent (development mode)"); | |
| await this.markMessageSent(data.messageId); | |
| return; | |
| } | |
| try { | |
| const { Resend } = await Promise.resolve().then(() => __importStar(require("resend"))); | |
| const resend = new Resend(this.resendApiKey); | |
| const result = await resend.emails.send({ | |
| from: 'MicProtocol <noreply@micprotocol.io>', | |
| to: data.to, | |
| subject: data.subject, | |
| html: data.bodyHtml, | |
| text: data.bodyText, | |
| }); | |
| this.logger.log(`Email sent successfully to ${data.to}, Resend ID: ${result.data?.id}`); | |
| await this.markMessageSent(data.messageId); | |
| } | |
| catch (error) { | |
| this.logger.error(`Failed to send email to ${data.to}`, error); | |
| throw error; | |
| } | |
| } | |
| async markMessageSent(messageId) { | |
| await this.prisma.outreachMessage.update({ | |
| where: { id: messageId }, | |
| data: { | |
| sentAt: new Date(), | |
| }, | |
| }); | |
| } | |
| async handleScheduleMessage(data) { | |
| this.logger.log(`Scheduling message ${data.messageId} for sequence ${data.sequenceId}`); | |
| this.logger.log(`Message ${data.messageId} scheduled for delivery`); | |
| } | |
| onCompleted(job) { | |
| this.logger.log(`Job ${job.id} completed successfully`); | |
| } | |
| onFailed(job, error) { | |
| this.logger.error(`Job ${job.id} failed: ${error.message}`, error.stack); | |
| } | |
| onStalled(jobId) { | |
| this.logger.warn(`Job ${jobId} has stalled`); | |
| } | |
| }; | |
| exports.OutreachProcessor = OutreachProcessor; | |
| __decorate([ | |
| (0, bullmq_1.OnWorkerEvent)("completed"), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [bullmq_2.Job]), | |
| __metadata("design:returntype", void 0) | |
| ], OutreachProcessor.prototype, "onCompleted", null); | |
| __decorate([ | |
| (0, bullmq_1.OnWorkerEvent)("failed"), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [bullmq_2.Job, Error]), | |
| __metadata("design:returntype", void 0) | |
| ], OutreachProcessor.prototype, "onFailed", null); | |
| __decorate([ | |
| (0, bullmq_1.OnWorkerEvent)("stalled"), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String]), | |
| __metadata("design:returntype", void 0) | |
| ], OutreachProcessor.prototype, "onStalled", null); | |
| exports.OutreachProcessor = OutreachProcessor = OutreachProcessor_1 = __decorate([ | |
| (0, bullmq_1.Processor)("outreach", { | |
| concurrency: 5, | |
| limiter: { | |
| max: 100, | |
| duration: 60000, | |
| }, | |
| }), | |
| (0, common_1.Injectable)(), | |
| __metadata("design:paramtypes", [prisma_service_1.PrismaService, | |
| config_1.ConfigService]) | |
| ], OutreachProcessor); | |
| //# sourceMappingURL=outreach.processor.js.map |