Files
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

51 lines
1.6 KiB
TypeScript

import { stringifyIO } from "@trigger.dev/core/v3";
import { findEnvironmentById } from "~/models/runtimeEnvironment.server";
import { TestTaskData } from "../testTask";
import { BaseService } from "./baseService.server";
import { TriggerTaskService } from "./triggerTask.server";
export class TestTaskService extends BaseService {
public async call(userId: string, data: TestTaskData) {
const authenticatedEnvironment = await findEnvironmentById(data.environmentId);
if (!authenticatedEnvironment) {
return;
}
const triggerTaskService = new TriggerTaskService();
switch (data.triggerSource) {
case "STANDARD":
return await triggerTaskService.call(data.taskIdentifier, authenticatedEnvironment, {
payload: data.payload,
options: {
test: true,
},
});
case "SCHEDULED": {
const payload = {
scheduleId: "sched_1234",
type: "IMPERATIVE",
timestamp: data.timestamp,
lastTimestamp: data.lastTimestamp,
timezone: data.timezone,
externalId: data.externalId,
upcoming: [],
};
const payloadPacket = await stringifyIO(payload);
return await triggerTaskService.call(
data.taskIdentifier,
authenticatedEnvironment,
{
payload: payloadPacket.data,
options: { payloadType: payloadPacket.dataType, test: true },
},
{ customIcon: "scheduled" }
);
}
default:
throw new Error("Invalid trigger source");
}
}
}