Files
triggerdotdev--trigger.dev/apps/webapp/app/v3/services/deleteTaskSchedule.server.ts
Matt Aitken 8ba9987944 Declarative schedules (#1226)
* Added type (STATIC or DYNAMIC) to TaskSchedule. Defaults to dynamic

* WIP with dev indexing of static schedules

* Added a code comment

* First stab at deleting unused static schedules

* Dashboard changes for the static schedules

* Generate the description. Upsert the instances when editing. Fix for the friendlyId

* Don’t allow deleting of static schedules

* Don’t allow enabling/disabling of static schedules

* Added filtering for schedule types

* Syncing of schedule for deployed tasks

* Static schedules are now created for each environment

* Added a second static schedule for testing

* Add the type to the schedule task run payload and the object you get back from the SDK

* Changed static/dynamic to declarative/imperative

* Timezone example

* Changeset

* Updated scheduled docs to include declarative

* When you test a schedule it set the type to “IMPERATIVE”

* Improved the tooltip

* Fix for queue time continuing to rise when a run is canceled/expired etc

* Update the info panel on a selected declarative schedule

* Check if there are no instances. This should never happen but log an error if it does

* Throw errors and push them through to the CLI dev command

* Fail deployments if creating the background tasks or schedules fails

* Format the deployment error so it gets displayed

* Changed the maxed out schedules error message to remove bit about support
2024-07-18 20:24:54 +01:00

56 lines
1.2 KiB
TypeScript

import { BaseService } from "./baseService.server";
type Options = {
projectId: string;
userId: string;
friendlyId: string;
};
export class DeleteTaskScheduleService extends BaseService {
public async call({ projectId, userId, friendlyId }: Options) {
//first check that the user has access to the project
const project = await this._prisma.project.findFirst({
where: {
id: projectId,
organization: {
members: {
some: {
userId,
},
},
},
},
});
if (!project) {
throw new Error("User does not have access to the project");
}
try {
const schedule = await this._prisma.taskSchedule.findFirst({
where: {
friendlyId,
},
});
if (!schedule) {
throw new Error("Schedule not found");
}
if (schedule.type === "DECLARATIVE") {
throw new Error("Cannot delete declarative schedules");
}
await this._prisma.taskSchedule.delete({
where: {
friendlyId,
},
});
} catch (e) {
throw new Error(
`Error deleting schedule: ${e instanceof Error ? e.message : JSON.stringify(e)}`
);
}
}
}