mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 04:29:01 +08:00
Nick: done (#1237)
This commit is contained in:
parent
5ab86b8b43
commit
b24ac0f6b5
@ -5,7 +5,7 @@ import { redlock } from "../redlock";
|
|||||||
import { supabase_service } from "../supabase";
|
import { supabase_service } from "../supabase";
|
||||||
import { createPaymentIntent } from "./stripe";
|
import { createPaymentIntent } from "./stripe";
|
||||||
import { issueCredits } from "./issue_credits";
|
import { issueCredits } from "./issue_credits";
|
||||||
import { sendNotification } from "../notification/email_notification";
|
import { sendNotification, sendNotificationWithCustomDays } from "../notification/email_notification";
|
||||||
import { NotificationType } from "../../types";
|
import { NotificationType } from "../../types";
|
||||||
import { deleteKey, getValue, setValue } from "../redis";
|
import { deleteKey, getValue, setValue } from "../redis";
|
||||||
import { redisRateLimitClient } from "../rate-limiter";
|
import { redisRateLimitClient } from "../rate-limiter";
|
||||||
@ -180,6 +180,26 @@ export async function autoCharge(
|
|||||||
HOURLY_COUNTER_EXPIRY,
|
HOURLY_COUNTER_EXPIRY,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check for frequent auto-recharges in the past week
|
||||||
|
const weeklyAutoRechargeKey = `auto-recharge-weekly:${chunk.team_id}`;
|
||||||
|
const weeklyRecharges = await redisRateLimitClient.incr(weeklyAutoRechargeKey);
|
||||||
|
// Set expiry for 7 days if not already set
|
||||||
|
await redisRateLimitClient.expire(weeklyAutoRechargeKey, 7 * 24 * 60 * 60);
|
||||||
|
|
||||||
|
// If this is the second auto-recharge in a week, send notification
|
||||||
|
if (weeklyRecharges >= 2) {
|
||||||
|
await sendNotificationWithCustomDays(
|
||||||
|
chunk.team_id,
|
||||||
|
NotificationType.AUTO_RECHARGE_FREQUENT,
|
||||||
|
7, // Send at most once per week
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error sending frequent auto-recharge notification: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
await sendNotification(
|
await sendNotification(
|
||||||
chunk.team_id,
|
chunk.team_id,
|
||||||
NotificationType.AUTO_RECHARGE_SUCCESS,
|
NotificationType.AUTO_RECHARGE_SUCCESS,
|
||||||
|
@ -34,6 +34,10 @@ const emailTemplates: Record<
|
|||||||
subject: "Auto recharge failed - Firecrawl",
|
subject: "Auto recharge failed - Firecrawl",
|
||||||
html: "Hey there,<br/><p>Your auto recharge failed. Please try again manually. If the issue persists, please reach out to us at <a href='mailto:help@firecrawl.com'>help@firecrawl.com</a></p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
html: "Hey there,<br/><p>Your auto recharge failed. Please try again manually. If the issue persists, please reach out to us at <a href='mailto:help@firecrawl.com'>help@firecrawl.com</a></p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
||||||
},
|
},
|
||||||
|
[NotificationType.AUTO_RECHARGE_FREQUENT]: {
|
||||||
|
subject: "Consider upgrading your plan - Firecrawl",
|
||||||
|
html: "Hey there,<br/><p>We've noticed frequent auto-recharges on your account. To optimize your costs and get better features, we recommend upgrading to a higher tier plan with:</p><ul><li>More included credits</li><li>Better pricing per credit</li><li>Higher rate limits</li></ul><p>View our plans at <a href='https://firecrawl.dev/pricing'>firecrawl.dev/pricing</a>. If none fit your needs, email us at <a href='mailto:help@firecrawl.com'>help@firecrawl.com</a> with 'Scale pricing' in the subject and we'll quickly help you move to a scale plan.</p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
||||||
|
},
|
||||||
[NotificationType.CONCURRENCY_LIMIT_REACHED]: {
|
[NotificationType.CONCURRENCY_LIMIT_REACHED]: {
|
||||||
subject: "You could be scraping faster - Firecrawl",
|
subject: "You could be scraping faster - Firecrawl",
|
||||||
html: `Hey there,
|
html: `Hey there,
|
||||||
|
@ -159,6 +159,7 @@ export enum NotificationType {
|
|||||||
AUTO_RECHARGE_SUCCESS = "autoRechargeSuccess",
|
AUTO_RECHARGE_SUCCESS = "autoRechargeSuccess",
|
||||||
AUTO_RECHARGE_FAILED = "autoRechargeFailed",
|
AUTO_RECHARGE_FAILED = "autoRechargeFailed",
|
||||||
CONCURRENCY_LIMIT_REACHED = "concurrencyLimitReached",
|
CONCURRENCY_LIMIT_REACHED = "concurrencyLimitReached",
|
||||||
|
AUTO_RECHARGE_FREQUENT = "autoRechargeFrequent",
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ScrapeLog = {
|
export type ScrapeLog = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user