Understanding the ScheduledTaskManager Interface
You can use the ScheduledTaskManager to schedule tasks. In the vSphere Client, scheduled tasks display in the Task & Events tab.
You can define actions to occur on vCenter Server at different times:
You can schedule scripts to be run or methods to be invoked on the server. You apply the action to an entity in the inventory, such as a virtual machine or a host.
You can perform the following actions with ScheduledTaskManager.
Retrieve scheduled tasks for a specific managed entity by calling the ScheduledTaskManager.RetrieveEntityScheduledTask method.
Create a scheduled task by calling the ScheduledTaskManager.CreateScheduledTask method. See Scheduling Tasks.
ScheduledTaskManager and ScheduledTask Managed Objects shows the ScheduledTaskManager service interface and associated data objects.
ScheduledTaskManager and ScheduledTask Managed Objects
The ScheduledTaskManager.scheduledTask property contains an array of the ScheduledTask objects configured for the server. If you have no actions scheduled, this property is empty. For any ScheduledTask objects in this array, you can use the info property of the ScheduledTask object to obtain information about the status of the scheduled action. Information includes the task’s progress, state, previous and next runtimes, and other details contained in the ScheduledTaskInfo data object.
If the action specified for a ScheduledTask creates its own Task (such as with any of the asynchronous operations), the managed object reference to the Task populates the activeTask property of ScheduledTaskInfo.
Scheduling Tasks
You create a ScheduledTask by invoking the ScheduledTaskManager.CreateScheduledTask method. When you invoke the method, you include a ScheduledTaskSpec object that defines the schedule and specifies the action to take at the specified time. A scheduled action applies to an object based on these rules:
If you specify a container object as the entity for the scheduled action, the schedule applies to all entities that are direct descendents of the container. You can set a ScheduledTask at the Folder, Datacenter, or VirtualApp level and have the scheduled action apply to all entities associated with the Folder, Datacenter, or VirtualApp.
Using ScheduledTaskManager to Create a ScheduledTask
Defining the Schedule and Action
The ScheduledTaskSpec data object contains all the information to create a ScheduledTask.
action – Action to take when the ScheduledTask runs. Specify an Action data object, which is an abstract type that is extended by several specific action types. The Action data objects are also used by the Alarm infrastructure. See Specifying Alarm Actions.
notification – Specifies the email address for sending notification messages about the ScheduledTask. To use notifications, the vCenter Server system must have an SMTP email gateway configured. By default, notification is set to an empty string.
scheduler – Specifies the time, frequency, and other details of the schedule. The TaskScheduler data object is the base type for several specific schedule objects. See Scheduling Recurring Operations.
Scheduling Recurring Operations
You can specify the times, days, or frequency of scheduled tasks by creating the appropriate instances of TaskScheduler subtypes and setting the scheduler property of the ScheduledTaskSpec.
The TaskScheduler base type has two properties:
activeTime is the time at which the action should occur. If you leave this property unset, it defaults to the time when that specification for the scheduled task was submitted to the server.
expireTime is the time after which the scheduled action should not occur. By default, this property is unset, so the scheduled task does not expire.
TaskScheduler Data Object Subtypes provides some usage information about the TaskScheduler subtypes. The examples in the table are Java code fragments.
Example: Schedule a task to run 10 minutes after vCenter Server startup.
Example: Schedule a task to run 30 minutes after the schedule is submitted to the server.
Base type for HourlyTaskScheduler, DailyTaskScheduler, WeeklyTaskScheduler, and MonthlyTaskScheduler objects. Set the interval property to define how frequently a task should run. For example, setting the interval property of an hourly task to 4 causes the task to run every 4 hours.
Example: Schedule a task to run every 4 hours at half-past the hour.
Example: Schedule a task to run daily at 9:30 am (EST).
Example: Schedule a task to run every Tuesday and Sunday at 30 minutes past midnight.
Example: Schedule a task to run every 3 months (on the last day of the month) at 12:30 p.m.
Example: Schedule a task to run on the last Wednesday of each month at 12:30 a.m.
The hour and minute properties of all objects that extend the RecurrentTaskSchedule data object are specified in Coordinated Universal Time (UTC) values rather than the local time of the server. When you define the schedule, convert your local time to a UTC value.
The code fragment in Example: Scheduled Task for Powering-on Virtual Machines defines a ScheduledTask that powers on virtual machines daily at 4:15 a.m., if the server local time is in the Pacific Standard Time (PST) time zone. For a server in the Eastern European Summer Time (EEST) zone, the setting is read by the system as 3:15 pm.
Example: Scheduled Task for Powering-on Virtual Machines
...
// Set the schedule using the DailyTaskScheduler subtype.
DailyTaskScheduler dTScheduler = new DailyTaskScheduler();
dTScheduler.setHour(12);
dTScheduler.setMinute(15);
ScheduledTaskSpec tSpec = new ScheduledTaskSpec();
tSpec.setDescription("Start virtual machine as per schedule.");
tSpec.setEnabled(Boolean=TRUE);
tSpec.setName("Power On Virtual Machine");
tSpec.setAction(ma);
tSpec.setScheduler(dTScheduler);
tSpec.setNotification("[email protected]");
my_conn.createScheduledTask(_sic.getScheduledTaskManager, vmRef, tSpec);
...
 
Cancelling a Scheduled Task
You can cancel a scheduled task in several ways.
To cancel the current run of a scheduled task, call ScheduledTask.RemoveScheduledTask. This method does not cancel subsequent runs of the ScheduledTask.
To cancel an upcoming run of a ScheduledTask, call ScheduledTask.ReconfigureScheduledTask with a new ScheduledTaskSpec data object containing the new specifications for the schedule.
To cancel a ScheduledTask that spawns a second task, create a PropertyCollector to obtain the reference to the Tasks and call its CancelTask method. The task must be cancellable.