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    String EXECUTION_COUNT_KEY = "executionCount";
22    String EXECUTION_FINISHED_KEY = "lastExecutionFinished";
23  
24    /**
25     * Get the type of the task. Implement this method to return the key for the type of task. This must be a read-only
26     * property.
27     *
28     * @return the type of task
29     */
30    TaskType getType();
31  
32    /**
33     * Get the description of the task.
34     *
35     * @return the description
36     */
37    String getDescription();
38  
39    /**
40     * Set the description of the task.
41     *
42     * @param description the description
43     */
44    void setDescription(String description);
45  
46    /**
47     * Handle the task progress event. Override this method to handle the progress of the task, e.g. by emitting
48     * {@code ServerSentEvent}s. The default is a no-op, which means no progress events will be emitted.
49     *
50     * @param event the task progress event
51     */
52    default void taskProgress(TaskProgressEvent event) {
53      // no-op
54    }
55  
56    /**
57     * Determine if this task can be stopped on demand (implements {@code InterruptableJob}).
58     *
59     * @return {@code true} if the task can be stopped on demand, false otherwise
60     * @see InterruptableJob
61     */
62    default boolean isInterruptable() {
63      return InterruptableJob.class.isAssignableFrom(this.getClass());
64    }
65  }