chore:little fixes and formating and linting and patches
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { CronQueueType } from '@openpanel/queue';
|
||||
import { cronQueue } from '@openpanel/queue';
|
||||
|
||||
import { logger } from './utils/logger';
|
||||
|
||||
async function removeConflictingJobs(schedulerKey: string) {
|
||||
@@ -137,7 +136,7 @@ export async function bootCron() {
|
||||
type: job.type,
|
||||
payload: undefined,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
// If upsert fails due to conflicting job, try to clean up and retry
|
||||
@@ -175,7 +174,7 @@ export async function bootCron() {
|
||||
type: job.type,
|
||||
payload: undefined,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
logger.info('Job scheduler created after cleanup', {
|
||||
job: job.type,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { logger } from '@/utils/logger';
|
||||
import { db, deleteFromClickhouse, deleteProjects } from '@openpanel/db';
|
||||
import type { CronQueuePayload } from '@openpanel/queue';
|
||||
import type { Job } from 'bullmq';
|
||||
import { logger } from '@/utils/logger';
|
||||
|
||||
export async function jobdeleteProjects(job: Job<CronQueuePayload>) {
|
||||
const projects = await db.project.findMany({
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import type { Job } from 'bullmq';
|
||||
import { differenceInDays } from 'date-fns';
|
||||
|
||||
import { db } from '@openpanel/db';
|
||||
import {
|
||||
type EmailData,
|
||||
type EmailTemplate,
|
||||
sendEmail,
|
||||
} from '@openpanel/email';
|
||||
import type { CronQueuePayload } from '@openpanel/queue';
|
||||
|
||||
import { getRecommendedPlan } from '@openpanel/payments';
|
||||
import type { CronQueuePayload } from '@openpanel/queue';
|
||||
import type { Job } from 'bullmq';
|
||||
import { differenceInDays } from 'date-fns';
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
// Types for the onboarding email system
|
||||
@@ -60,7 +58,7 @@ const getters = {
|
||||
return getRecommendedPlan(
|
||||
ctx.org.subscriptionPeriodEventsCount,
|
||||
(plan) =>
|
||||
`${plan.formattedEvents} events per month for ${plan.formattedPrice}`,
|
||||
`${plan.formattedEvents} events per month for ${plan.formattedPrice}`
|
||||
);
|
||||
},
|
||||
} as const;
|
||||
@@ -184,7 +182,7 @@ export async function onboardingJob(job: Job<CronQueuePayload>) {
|
||||
});
|
||||
orgsCompleted++;
|
||||
logger.info(
|
||||
`Completed onboarding for organization ${org.id} (all emails sent)`,
|
||||
`Completed onboarding for organization ${org.id} (all emails sent)`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -201,7 +199,7 @@ export async function onboardingJob(job: Job<CronQueuePayload>) {
|
||||
nextEmailDay: nextEmail.day,
|
||||
orgCreatedAt: org.createdAt,
|
||||
today: new Date(),
|
||||
},
|
||||
}
|
||||
);
|
||||
// Check if enough days have passed
|
||||
if (daysSinceOrgCreation < nextEmail.day) {
|
||||
@@ -220,7 +218,7 @@ export async function onboardingJob(job: Job<CronQueuePayload>) {
|
||||
});
|
||||
orgsCompleted++;
|
||||
logger.info(
|
||||
`Completed onboarding for organization ${org.id} (shouldSend returned complete)`,
|
||||
`Completed onboarding for organization ${org.id} (shouldSend returned complete)`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -247,7 +245,7 @@ export async function onboardingJob(job: Job<CronQueuePayload>) {
|
||||
|
||||
emailsSent++;
|
||||
logger.info(
|
||||
`Sent onboarding email "${nextEmail.template}" to organization ${org.id} (user ${user.id})`,
|
||||
`Sent onboarding email "${nextEmail.template}" to organization ${org.id} (user ${user.id})`
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
@@ -255,7 +253,7 @@ export async function onboardingJob(job: Job<CronQueuePayload>) {
|
||||
{
|
||||
error,
|
||||
template: nextEmail.template,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TABLE_NAMES, chQuery } from '@openpanel/db';
|
||||
import { chQuery, TABLE_NAMES } from '@openpanel/db';
|
||||
|
||||
export async function ping() {
|
||||
if (process.env.DISABLE_PING) {
|
||||
@@ -6,7 +6,7 @@ export async function ping() {
|
||||
}
|
||||
|
||||
const [res] = await chQuery<{ count: number }>(
|
||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
|
||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`
|
||||
);
|
||||
|
||||
if (typeof res?.count === 'number') {
|
||||
|
||||
@@ -47,7 +47,7 @@ export async function salt() {
|
||||
} catch (error) {
|
||||
if (retryCount < ALLOWED_RETRIES) {
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, BASE_DELAY * 2 ** retryCount),
|
||||
setTimeout(resolve, BASE_DELAY * 2 ** retryCount)
|
||||
);
|
||||
return generateNewSaltWithRetry(retryCount + 1);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
import { eventBuffer, groupBuffer, profileBackfillBuffer, profileBuffer, replayBuffer, sessionBuffer } from '@openpanel/db';
|
||||
import {
|
||||
eventBuffer,
|
||||
groupBuffer,
|
||||
profileBackfillBuffer,
|
||||
profileBuffer,
|
||||
replayBuffer,
|
||||
sessionBuffer,
|
||||
} from '@openpanel/db';
|
||||
import type { CronQueuePayload } from '@openpanel/queue';
|
||||
|
||||
import type { Job } from 'bullmq';
|
||||
import { jobdeleteProjects } from './cron.delete-projects';
|
||||
import { gscSyncAllJob } from './gsc';
|
||||
import { onboardingJob } from './cron.onboarding';
|
||||
import { ping } from './cron.ping';
|
||||
import { salt } from './cron.salt';
|
||||
import { gscSyncAllJob } from './gsc';
|
||||
import { insightsDailyJob } from './insights';
|
||||
|
||||
export async function cronJob(job: Job<CronQueuePayload>) {
|
||||
|
||||
@@ -39,13 +39,13 @@ export async function insightsDailyJob(job: Job<CronQueuePayload>) {
|
||||
},
|
||||
{
|
||||
jobId: `daily:${date}:${projectId}`, // idempotent
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function insightsProjectJob(
|
||||
job: Job<InsightsQueuePayloadProject>,
|
||||
job: Job<InsightsQueuePayloadProject>
|
||||
) {
|
||||
const { projectId, date } = job.data.payload;
|
||||
const engine = createEngine({
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { MiscQueuePayloadTrialEndingSoon } from '@openpanel/queue';
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
export async function trialEndingSoonJob(
|
||||
job: Job<MiscQueuePayloadTrialEndingSoon>,
|
||||
job: Job<MiscQueuePayloadTrialEndingSoon>
|
||||
) {
|
||||
const { organizationId } = job.data.payload;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
import type { MiscQueuePayloadTrialEndingSoon } from '@openpanel/queue';
|
||||
|
||||
import type { Job } from 'bullmq';
|
||||
import { trialEndingSoonJob } from './misc.trail-ending-soon';
|
||||
|
||||
export async function miscJob(job: Job<MiscQueuePayloadTrialEndingSoon>) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
import { Prisma, db } from '@openpanel/db';
|
||||
import { db, Prisma } from '@openpanel/db';
|
||||
import { sendDiscordNotification } from '@openpanel/integrations/src/discord';
|
||||
import { sendSlackNotification } from '@openpanel/integrations/src/slack';
|
||||
import { execute as executeJavaScriptTemplate } from '@openpanel/js-runtime';
|
||||
import type { NotificationQueuePayload } from '@openpanel/queue';
|
||||
import { publishEvent } from '@openpanel/redis';
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
function isValidJson<T>(
|
||||
value: T | Prisma.NullableJsonNullValueInput | null | undefined,
|
||||
value: T | Prisma.NullableJsonNullValueInput | null | undefined
|
||||
): value is T {
|
||||
return (
|
||||
value !== null &&
|
||||
@@ -60,7 +59,7 @@ export async function notificationJob(job: Job<NotificationQueuePayload>) {
|
||||
) {
|
||||
const result = executeJavaScriptTemplate(
|
||||
integration.config.javascriptTemplate,
|
||||
payload.event,
|
||||
payload.event
|
||||
);
|
||||
body = result;
|
||||
} else {
|
||||
@@ -96,7 +95,7 @@ export async function notificationJob(job: Job<NotificationQueuePayload>) {
|
||||
return sendSlackNotification({
|
||||
webhookUrl: integration.config.incoming_webhook.url,
|
||||
message: [`🔔 *${notification.title}*`, notification.message].join(
|
||||
'\n',
|
||||
'\n'
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
import type { SessionsQueuePayload } from '@openpanel/queue';
|
||||
|
||||
import { logger } from '@/utils/logger';
|
||||
import {
|
||||
db,
|
||||
getOrganizationBillingEventsCount,
|
||||
getProjectEventsCount,
|
||||
} from '@openpanel/db';
|
||||
import type { SessionsQueuePayload } from '@openpanel/queue';
|
||||
import { cacheable } from '@openpanel/redis';
|
||||
import type { Job } from 'bullmq';
|
||||
import { createSessionEnd } from './events.create-session-end';
|
||||
import { logger } from '@/utils/logger';
|
||||
|
||||
export async function sessionsJob(job: Job<SessionsQueuePayload>) {
|
||||
const res = await createSessionEnd(job);
|
||||
@@ -22,7 +20,7 @@ export async function sessionsJob(job: Job<SessionsQueuePayload>) {
|
||||
}
|
||||
|
||||
const updateEventsCount = cacheable(async function updateEventsCount(
|
||||
projectId: string,
|
||||
projectId: string
|
||||
) {
|
||||
const organization = await db.organization.findFirst({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user