Merge branch 'main' into main
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import cron from "node-cron";
|
import cron from "node-cron";
|
||||||
import signale from "signale";
|
import signale from "signale";
|
||||||
import { API_URI } from "./constants";
|
|
||||||
|
|
||||||
export const task = cron.schedule("* * * * *", () => {
|
import { Identities } from "../controllers/Identities";
|
||||||
|
import { Tasks } from "../controllers/Tasks";
|
||||||
|
|
||||||
|
export const task = cron.schedule("* * * * *", async () => {
|
||||||
signale.info("Running scheduled tasks");
|
signale.info("Running scheduled tasks");
|
||||||
try {
|
try {
|
||||||
void fetch(`${API_URI}/tasks`, {
|
await (new Tasks().handleTasks());
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
signale.error("Failed to run scheduled tasks. Please check the error below");
|
signale.error("Failed to run scheduled tasks. Please check the error below");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -15,9 +15,7 @@ export const task = cron.schedule("* * * * *", () => {
|
|||||||
|
|
||||||
signale.info("Updating verified identities");
|
signale.info("Updating verified identities");
|
||||||
try {
|
try {
|
||||||
void fetch(`${API_URI}/identities/update`, {
|
await (new Identities().updateIdentities());
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
signale.error("Failed to update verified identities. Please check the error below");
|
signale.error("Failed to update verified identities. Please check the error below");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
@@ -99,7 +99,12 @@ export class Identities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post("update")
|
@Post("update")
|
||||||
public async updateIdentities(req: Request, res: Response) {
|
public async updateIdentitiesApi(req: Request, res: Response) {
|
||||||
|
await (new Identities().updateIdentities());
|
||||||
|
return res.status(200).json({ success: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateIdentities() {
|
||||||
const count = await prisma.project.count({
|
const count = await prisma.project.count({
|
||||||
where: { email: { not: null } },
|
where: { email: { not: null } },
|
||||||
});
|
});
|
||||||
@@ -155,8 +160,6 @@ export class Identities {
|
|||||||
await redis.del(Keys.Project.public(project.public));
|
await redis.del(Keys.Project.public(project.public));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({ success: true });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import { ProjectService } from "../services/ProjectService";
|
|||||||
@Controller("tasks")
|
@Controller("tasks")
|
||||||
export class Tasks {
|
export class Tasks {
|
||||||
@Post()
|
@Post()
|
||||||
public async handleTasks(req: Request, res: Response) {
|
public async handleTasksApi(req: Request, res: Response) {
|
||||||
|
await (new Tasks().handleTasks());
|
||||||
|
return res.status(200).json({ success: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async handleTasks() {
|
||||||
// Get all tasks with a runBy data in the past
|
// Get all tasks with a runBy data in the past
|
||||||
const tasks = await prisma.task.findMany({
|
const tasks = await prisma.task.findMany({
|
||||||
where: { runBy: { lte: new Date() } },
|
where: { runBy: { lte: new Date() } },
|
||||||
@@ -128,7 +133,5 @@ export class Tasks {
|
|||||||
|
|
||||||
signale.success(`Task completed for ${contact.email} from ${project.name}`);
|
signale.success(`Task completed for ${contact.email} from ${project.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({ success: true });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user