mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-12 15:05:19 +00:00
Refactor enterprise backup cron job initialization: Simplified the cron job setup by consolidating user retrieval and validation logic into a single scheduled job. Updated the schedule to run every 3 days and removed redundant checks for user length.
This commit is contained in:
@@ -5,32 +5,22 @@ import { db } from "../../db/index";
|
|||||||
import { user as userSchema } from "../../db/schema/user";
|
import { user as userSchema } from "../../db/schema/user";
|
||||||
|
|
||||||
export const initEnterpriseBackupCronJobs = async () => {
|
export const initEnterpriseBackupCronJobs = async () => {
|
||||||
const users = await db.query.user.findMany({
|
scheduleJob("enterprise-check", "0 0 */3 * *", async () => {
|
||||||
where: and(
|
const users = await db.query.user.findMany({
|
||||||
isNotNull(userSchema.licenseKey),
|
where: and(
|
||||||
isNotNull(userSchema.enableEnterpriseFeatures),
|
isNotNull(userSchema.licenseKey),
|
||||||
eq(userSchema.isValidEnterpriseLicense, true),
|
isNotNull(userSchema.enableEnterpriseFeatures),
|
||||||
),
|
eq(userSchema.isValidEnterpriseLicense, true),
|
||||||
});
|
),
|
||||||
|
});
|
||||||
if (users.length === 0) {
|
for (const user of users) {
|
||||||
return;
|
if (user.isValidEnterpriseLicense) {
|
||||||
}
|
console.log(
|
||||||
|
"Validating license key....",
|
||||||
console.log(
|
user.firstName,
|
||||||
"Setting up enterprise backup cron jobs for users....",
|
user.lastName,
|
||||||
users.length,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
for (const user of users) {
|
|
||||||
if (user.isValidEnterpriseLicense) {
|
|
||||||
scheduleJob(`enterprise-backup-${user.id}`, "0 0 */14 * *", async () => {
|
|
||||||
try {
|
try {
|
||||||
console.log(
|
|
||||||
"Validating license key....",
|
|
||||||
user.firstName,
|
|
||||||
user.lastName,
|
|
||||||
);
|
|
||||||
const isValid = await validateLicenseKey(user.licenseKey || "");
|
const isValid = await validateLicenseKey(user.licenseKey || "");
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
throw new Error("License key is invalid");
|
throw new Error("License key is invalid");
|
||||||
@@ -41,9 +31,9 @@ export const initEnterpriseBackupCronJobs = async () => {
|
|||||||
.set({ isValidEnterpriseLicense: false })
|
.set({ isValidEnterpriseLicense: false })
|
||||||
.where(eq(userSchema.id, user.id));
|
.where(eq(userSchema.id, user.id));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const validateLicenseKey = async (licenseKey: string) => {
|
export const validateLicenseKey = async (licenseKey: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user