View Javadoc
1   /*
2    * Copyright (C) 2024 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
5    */
6   package org.tailormap.api.scheduling;
7   
8   import org.quartz.InterruptableJob;
9   import org.tailormap.api.admin.model.TaskProgressEvent;
10  
11  public interface Task {
12  
13    String TYPE_KEY = "type";
14    String DESCRIPTION_KEY = "description";
15    String UUID_KEY = "uuid";
16    String CRON_EXPRESSION_KEY = "cronExpression";
17    String PRIORITY_KEY = "priority";
18    String STATE_KEY = "state";
19    String LAST_RESULT_KEY = "lastResult";
20    String INTERRUPTABLE_KEY = "interruptable";
21  
22    /**
23     * Get the type of the task. Implement this method to return the key for the type of task. This
24     * must be a read-only property.
25     *
26     * @return the type of task
27     */
28    TaskType getType();
29  
30    /**
31     * Get the description of the task.
32     *
33     * @return the description
34     */
35    String getDescription();
36  
37    /**
38     * Set the description of the task.
39     *
40     * @param description the description
41     */
42    void setDescription(String description);
43  
44    /**
45     * Handle the task progress event. Override this method to handle the progress of the task, e.g.
46     * by emitting {@code ServerSentEvent}s. The default is a no-op.
47     *
48     * @param event the task progress event
49     */
50    default void taskProgress(TaskProgressEvent event) {
51      // no-op
52    }
53  
54    /**
55     * Determine if this task can be stopped on demand (implements {@code InterruptableJob}).
56     *
57     * @return {@code true} if the task can be stopped on demand, false otherwise
58     * @see InterruptableJob
59     */
60    default boolean isInterruptable() {
61      return InterruptableJob.class.isAssignableFrom(this.getClass());
62    }
63  }