rPath Appliance Platform:Plugin Tasks
From rPath Wiki
|
Types of Tasks
The appliance agent provides a scheduling model for tasks that features three types of task scheduling:
- Immediate Tasks scheduled to execute once, usually within 5 seconds; this is equivalent to manually launching the task
- One Time Tasks scheduled to be executed once; these often include long-running tasks to be scheduled as resources permit
- Recurring Tasks with flexible and repeatable schedules, such as hourly, daily, weekly, and monthly
As described in rPath Appliance Platform Plugin Structure, the action of an Appliance Platform plugin is driven by tasks handled by the web and service components, and the web component can request either immediate or scheduled execution (recurring or one time) by the service component.
Immediate Tasks
Use immediate tasks for actions which complete quickly and require elevated privileges (such as changing the root password). The call for execution made by the web component waits for the service component to complete the task. This should only be used for operations that will take less than 4-5 seconds to complete. An immediate tasks is equal to scheduling the task to occur immediately.
One Time Tasks
Use one time tasks for actions which need to be executed a single time. A plugin that utilizes this type of scheduling is the backup plugin. The task executed by this plugin runs a single time when backup now is selected.
Recurring Tasks
Use recurring tasks for actions which need to be scheduled. The schedule is adjustable to any period of time: weekly, monthly, daily, and so on. A plugin that utilizes this type of scheduling is the backup plugin when you select schedule updates.
Implement a Task
To implement any of these tasks, create an instance from one of the available schedule classes that derive from raa.db.schedule.Schedule. Some of the available schedule classes repeat periodically.
When rAPA executes the service component of the plugin, the schedule ID and a unique execution identifier (execution ID) are passed to the service component. A repeating schedule can cause the service component to be executed multiple times. Each execution of the component corresponds to the same schedule ID and has its own execution ID, which is unique across the system.
The service component may require additional knowledge about the task it is executing. If so, it can perform an XMLRPC call to its associated web component to determine such information. The service component can refer to the proxy for its web component as self.server, and can refer to the root controller proxy as self.rootserver.
Use self.schedule() with the previously created schedule as an argument to initialize the scheduled task. This method returns a schedule identifier (schedule ID). If you need to remember information about this specific tasks for use in other tasks, store information associated with the schedule ID in the plugin's database table.
Immediate Tasks
| Call | Description |
|---|---|
| ScheduleImmed | This class is used to execute a task immediately. This class should be used for immediate tasks that will complete in a few seconds. |
| ScheduleNow | This class is used to execute a task immediately. This class should be used for immediate tasks that take longer than a few seconds to complete. |
Scheduled Tasks (One Time and Recurring)
| Call | Description |
|---|---|
| ScheduleInterval | A generic class for setting up schedules to repeat with specific intervals |
| ScheduleWeekly | A class for setting up a task to repeat weekly on a specific day. |
| ScheduleMonthlyRelative | This class sets up a weekly schedule on a specific day that repeats either the first, second, third, or fourth week of each month. |
| ScheduleMonthlyAbsolute | This class allows the choice of specific day of month for a task to execute. |
| ScheduleOnce | This function should be used with the base class raa.db.schedule.Schedule to schedule tasks that execute a single time. |
