|
16 | 16 | import dev.dbos.transact.workflow.ForkOptions; |
17 | 17 | import dev.dbos.transact.workflow.ListWorkflowsInput; |
18 | 18 | import dev.dbos.transact.workflow.Queue; |
| 19 | +import dev.dbos.transact.workflow.ScheduleStatus; |
19 | 20 | import dev.dbos.transact.workflow.SerializationStrategy; |
20 | 21 | import dev.dbos.transact.workflow.StepInfo; |
21 | 22 | import dev.dbos.transact.workflow.StepOptions; |
22 | 23 | import dev.dbos.transact.workflow.VersionInfo; |
23 | 24 | import dev.dbos.transact.workflow.Workflow; |
24 | 25 | import dev.dbos.transact.workflow.WorkflowClassName; |
25 | 26 | import dev.dbos.transact.workflow.WorkflowHandle; |
| 27 | +import dev.dbos.transact.workflow.WorkflowSchedule; |
26 | 28 | import dev.dbos.transact.workflow.WorkflowStatus; |
27 | 29 |
|
28 | 30 | import java.io.IOException; |
29 | 31 | import java.io.InputStream; |
30 | 32 | import java.lang.reflect.Method; |
31 | 33 | import java.time.Duration; |
| 34 | +import java.time.Instant; |
| 35 | +import java.time.ZoneId; |
32 | 36 | import java.util.Collection; |
33 | 37 | import java.util.HashSet; |
34 | 38 | import java.util.List; |
@@ -759,6 +763,122 @@ public void setLatestApplicationVersion(@NonNull String versionName) { |
759 | 763 | ensureLaunched("setLatestApplicationVersion").setLatestApplicationVersion(versionName); |
760 | 764 | } |
761 | 765 |
|
| 766 | + /** |
| 767 | + * Create a cron schedule that periodically invokes a workflow. The scheduleId is generated if |
| 768 | + * null. |
| 769 | + * |
| 770 | + * @param schedule the schedule configuration |
| 771 | + */ |
| 772 | + public void createSchedule( |
| 773 | + @NonNull String scheduleName, |
| 774 | + @NonNull String workflowName, |
| 775 | + @NonNull String className, |
| 776 | + @NonNull String schedule, |
| 777 | + @Nullable Object context, |
| 778 | + boolean backfill, |
| 779 | + @Nullable ZoneId cronTimeZone, |
| 780 | + @Nullable String queueName) { |
| 781 | + ensureLaunched("createSchedule") |
| 782 | + .createSchedule( |
| 783 | + scheduleName, |
| 784 | + workflowName, |
| 785 | + className, |
| 786 | + schedule, |
| 787 | + context, |
| 788 | + backfill, |
| 789 | + cronTimeZone, |
| 790 | + queueName); |
| 791 | + } |
| 792 | + |
| 793 | + /** |
| 794 | + * Get a schedule by name. |
| 795 | + * |
| 796 | + * @param name schedule name |
| 797 | + * @return the schedule, or empty if not found |
| 798 | + */ |
| 799 | + public @NonNull Optional<WorkflowSchedule> getSchedule(@NonNull String name) { |
| 800 | + return ensureLaunched("getSchedule").getSchedule(name); |
| 801 | + } |
| 802 | + |
| 803 | + /** |
| 804 | + * List schedules with optional filters. |
| 805 | + * |
| 806 | + * @param status filter by status (e.g. "ACTIVE", "PAUSED"); null means no filter |
| 807 | + * @param workflowName filter by workflow name; null means no filter |
| 808 | + * @param namePrefix filter by schedule name prefix; null means no filter |
| 809 | + * @return matching schedules |
| 810 | + */ |
| 811 | + public @NonNull List<WorkflowSchedule> listSchedules( |
| 812 | + @Nullable List<ScheduleStatus> status, |
| 813 | + @Nullable List<String> workflowName, |
| 814 | + @Nullable List<String> namePrefix) { |
| 815 | + return ensureLaunched("listSchedules").listSchedules(status, workflowName, namePrefix); |
| 816 | + } |
| 817 | + |
| 818 | + /** |
| 819 | + * Delete a schedule by name. No-op if the schedule does not exist. |
| 820 | + * |
| 821 | + * @param name schedule name |
| 822 | + */ |
| 823 | + public void deleteSchedule(@NonNull String name) { |
| 824 | + ensureLaunched("deleteSchedule").deleteSchedule(name); |
| 825 | + } |
| 826 | + |
| 827 | + /** |
| 828 | + * Pause a schedule. A paused schedule does not fire. |
| 829 | + * |
| 830 | + * @param name schedule name |
| 831 | + */ |
| 832 | + public void pauseSchedule(@NonNull String name) { |
| 833 | + ensureLaunched("pauseSchedule").pauseSchedule(name); |
| 834 | + } |
| 835 | + |
| 836 | + /** |
| 837 | + * Resume a paused schedule so it begins firing again. |
| 838 | + * |
| 839 | + * @param name schedule name |
| 840 | + */ |
| 841 | + public void resumeSchedule(@NonNull String name) { |
| 842 | + ensureLaunched("resumeSchedule").resumeSchedule(name); |
| 843 | + } |
| 844 | + |
| 845 | + /** |
| 846 | + * Atomically create or replace a set of schedules. Each schedule is deleted (if it exists) and |
| 847 | + * re-created in a single transaction. |
| 848 | + * |
| 849 | + * @param schedules the schedules to apply |
| 850 | + */ |
| 851 | + public void applySchedules(@NonNull List<WorkflowSchedule> schedules) { |
| 852 | + ensureLaunched("applySchedules").applySchedules(schedules); |
| 853 | + } |
| 854 | + |
| 855 | + // /** |
| 856 | + // * Enqueue all executions of a schedule that would have run between {@code start} (exclusive) |
| 857 | + // and |
| 858 | + // * {@code end} (exclusive). Uses the same deterministic workflow IDs as the live scheduler, so |
| 859 | + // * already-executed times are skipped. |
| 860 | + // * |
| 861 | + // * @param scheduleName name of an existing schedule |
| 862 | + // * @param start start of the backfill window (exclusive) |
| 863 | + // * @param end end of the backfill window (exclusive) |
| 864 | + // * @return handles to the enqueued executions |
| 865 | + // */ |
| 866 | + public @NonNull List<WorkflowHandle<Object, Exception>> backfillSchedule( |
| 867 | + @NonNull String scheduleName, @NonNull Instant start, @NonNull Instant end) { |
| 868 | + return ensureLaunched("backfillSchedule").backfillSchedule(scheduleName, start, end); |
| 869 | + } |
| 870 | + |
| 871 | + // /** |
| 872 | + // * Immediately enqueue the scheduled workflow at the current time. |
| 873 | + // * |
| 874 | + // * @param scheduleName name of an existing schedule |
| 875 | + // * @return handle to the enqueued execution |
| 876 | + // */ |
| 877 | + public <T, E extends Exception> @NonNull WorkflowHandle<T, E> triggerSchedule( |
| 878 | + @NonNull String scheduleName) { |
| 879 | + return ensureLaunched("triggerSchedule").triggerSchedule(scheduleName); |
| 880 | + } |
| 881 | + |
762 | 882 | /** |
763 | 883 | * Retrieve a handle to a workflow, given its ID. Note that a handle is always returned, whether |
764 | 884 | * the workflow exists or not; getStatus() can be used to tell the difference |
|
0 commit comments