Using the Appkit Tasks Module
pom.xml
file:executor.conf
and place this in src/main/resources/conf/services/task/
. Within that file, these parameters can be set:max-tasks-in-memory
: the maximum number of tasks the registry can hold in memory at any one time. The default is 100.max-tasks-on-disk
: the maximum number of tasks that can be persisted on disk. The default is 10000000.disk-store-location
: the location for storing/persisting tasks. The default is java.io.tmpdir
- a JVM system property that will change depending on your Operating System.time-to-idle
: the amount of time in seconds a task is allowed to be left idle (from last access or modified date) before being removed from the registry. The default is 3600.time-to-live
: the amount of time in seconds a task is allowed to exist (from its creation date) before being removed from the registry regardless of how often it is used. The default is effectively forever.overflow-to-disk
: whether additional tasks will be stored on disk, if the in-memory registry is full. The default is true.persist-to-disk
: whether tasks will be persisted to disk, for example, if the if in-memory registry is full or the application shuts down. The default is true.As noted, all of the above parameters already contain default values that will be used in case executor.conf
cannot be found or one or other of the parameters is not defined.start
), when it is stopped (stop
), and when it is deleted (delete
) from the registry. These methods are named when particular RESTful endpoints are hit as discussed below.resources/conf
, for example, resources/conf/tasks/download.conf
. The simplest configuration for a task would be one with just the name
parameter:name
is the fully-qualified class name of the Java class you have written to define your Task
.The configuration can also include a display name, as well as any other attributes that the task might need, for example:getAttributes()
.GET /twigkit/api/tasks
: this will get a list of tasks owned by the current user.GET /twigkit/api/tasks/{id}
: this will get any information on the task with the given ID, including status and any task-specific attributes.GET /twigkit/api/tasks/{id}/status
this will get the status of the task with the given ID.POST /twigkit/api/tasks/{task}
: this will submit a task with the given configuration task name to the task executor. The given task name is the configuration name for a task. For example, if the configuration for a particular task was stored in resources/conf/tasks/download.conf
, the task name passed to the submit endpoint would be tasks.download
.POST /twigkit/api/tasks/{id}/stop
: this will stop the task with the given ID.POST /twigkit/api/tasks/{id}/restart
: this will restart the task with the given IDDELETE /twigkit/api/tasks/{id}
: this will cancel the task with the given ID. This will call stop
and delete
on the task as well as remove the task from the registry.disk-store-location
(see above) a task-cache.data
file is created to keep track of tasks until the application shuts down when an additional file,task-cache.index
, is created to persist tasks. Next time the application is run these tasks will be available for continued use.To disable task persistence, set the configuration parameters overflow-to-disk
and persist-to-disk
to false
.time-to-live
This is the amount of time in seconds a task is allowed to exist before being removed from the registry regardless of how often it is used. The default is effectively forever. This is useful in case resources are limited and it is not clear whether tasks will be used after a finite amount of time.
time-to-idle
This is the amount of time in seconds a task is allowed to be left idle before being removed from the registry. The default is one hour.
time-to-live
and time-to-idle
to 0.delete
method implemented within your task will be named. If there is any final action that you would like your task to perform before it is removed then you can implement that action in the tasks delete
method.max-tasks-on-disk
then the least recently used task will be evicted from the registry. The default maximum number of tasks that can be stored on disk is 10000000.If instead you decide not to store tasks on disk (both overflow-to-disk
and persist-to-disk
are false
) but would like to limit the number of tasks that can be stored in-memory, then the configuration parameter max-tasks-in-memory
can be set. This will evict the least recently used task once capacity is reached.delete
method implemented within your task will be named. If there is any final action that you would like your task to perform before it is removed then you can implement that action in the tasks delete
method.