Administering Scheduled Tasks
Scheduled Tasks are regularly timed tasks that can run every few seconds, every day, every week, etc.
Task scheduler went through a complete overhaul in OpenMRS 2.9.x. It is now based on JobRunr.
The old tasks extending the Task class and using TaskDefinition are still supported though module authors are encouraged to migrate to new TaskHandler and TaskData classes. You may still preview and adjust old tasks from the legacy interface (see below).
The primary update in the API involves the implementation of security and access control for scheduled tasks. The service now enforces authorization rules ensuring that users can only view or manage tasks they created, unless they possess the Manage Scheduler privilege. This logic is applied consistently across retrieval methods (getTask, getRecurringTask, getTasks, getRecurringTasks).
Additionally, the getTasks method has been implemented using a custom Spliterator to handle efficient streaming and pagination. Instead of loading all jobs into memory, it lazily fetches pages of jobs from the storage provider. It then filters these batches on-the-fly based on the authenticated user's privileges, ensuring that the returned Stream<TaskDetails> is both secure and performant, even when handling large numbers of background jobs. The same filtering is applied to getRecurringTasks.
Finally, the scheduling methods (schedule, scheduleRecurrently) now explicitly capture the systemId of the creating user. This is passed into the JobRequestAdapter, allowing the ownership of the job to be persisted and later verified against the authenticated user during retrieval.
It is also possible to manage the scheduled tasks via a dedicated scheduler dashboard. It is disabled by default (except for docker compose development setup) and can be enabled by setting the following properties in openmrs-runtime.properties.
jobrunr.dashboard.enabled=true
jobrunr.dashboard.username=admin
jobrunr.dashboard.password=someStrongPasswordForAdmin
jobrunr.dashboard.port=9000It is accessible on a separate port than the OpenMRS instance and can be accessed via http://localhost:9000 by default.
OpenMRS versions prior to 2.9.x
See Admin-->Manager Scheduled Tasks for the administration of them.
A task is just a Java class that is registered in OpenMRS by being in the scheduled_task_config table. Typically Modules provide these tasks.
You can edit the properties of a task by clicking through to it.
Prior to v1.7 of OpenMRS you had to set a username/password used to run tasks in your openmrs-runtime.properties file. This lets the tasks authenticate to openmrs to do their things. (After 1.7 you can delete this entry because tasks run as the "root" user by default)
There are a number of default tasks provided:
Process Form Entry Queue - used by the formentry to process xml into hl7
Process HL7 Task - reads the HL7 In Queue table and turns them into rows in encounter/obs/patient/etc
Alert Reminder Task
Send Email Task
Hello World Task
Check Internet Connectivity Task - tries to reach google.com and adds an Alert
Update Concept Words - reprocesses all concept names (see Admin --> Update Concept Words page)
Generate Data Export - takes in a comma separated "dataExportIds" argument which specifies which Data Exports (reportingcompatibility module) to generate
: org.openmrs.scheduler.tasks.GenerateDataExportTask
Auto-deactivate users task