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.

The following table provides some usage information about the TaskScheduler subtypes. The examples in the table are Java code fragments.

TaskScheduler Subtype Usage
AfterStartupTaskScheduler

Schedule a task to start as soon as the vCenter Server system is started, or at a defined time after startup. The value must be zero (task triggered at startup) or higher.

Example: Schedule a task to run 10 minutes after vCenter Server startup.

AfterStartupTaskScheduler asts =
    new	AfterStartupTaskScheduler();

asts.setMinute(10);

OnceTaskScheduler

Schedule an action to run once only at the specified date and time.

Example: Schedule a task to run 30 minutes after the schedule is submitted to the server.

Calendar runTime = Calendar.getInstance();
runtime.add(Calendar.MINUTE, 30);
OnceTaskScheduler ots = new OnceTaskScheduler();
ots.setRunAt(runTime);
RecurrentTaskScheduler 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.
HourlyTaskScheduler

Schedule a task to run once every hour (or every specified number of hours) at a specified time. Set the interval property to run the task after a specified number of hours.

Example: Schedule a task to run every 4 hours at half-past the hour.

HourlyTaskScheduler hts =
    new HourlyTaskScheduler();
hts.setMinute(30);
hts.setInterval(4);
DailyTaskScheduler

Schedule a task to run daily or a specified number of days at a specified time (hour and minutes). Use in conjunction with the interval property to run the task after a specified number of days.

Example: Schedule a task to run daily at 9:30 am (EST).

DailyTaskScheduler dts =
    new DailyTaskScheduler();
dts.setMinute(30);
dts.setHour(14);
WeeklyTaskScheduler

Schedule a task to run every week (or every specified number of weeks) on a specified day (or days) at a specific time. The hours and minutes are set as UTC values. At least one of the boolean values must be set to true. You can also set the interval property to run the task after a specified number of weeks.

Example: Schedule a task to run every Tuesday and Sunday at 30 minutes past midnight.

WeeklyTaskScheduler wts =
   new WeeklyTaskScheduler();
wts.setMonday(true);
wts.setTuesday(true);
...
wts.setSaturday(false);
wts.setSunday(true);
dts.setMinute(30);
dts.setHour(4);
MonthlyByDayTaskScheduler

Schedule a task to run every month (or every specified number of months) on a specified day at a specified time (hour and minutes). You can also set the interval property to run the task after a specified number of months.

Example: Schedule a task to run every 3 months (on the last day of the month) at 12:30 p.m.

MonthlyByDayTaskScheduler mbdts = 
   new MonthlyByDayTaskScheduler();
mbdts.setDay(31);
mbdts.setInterval(3);
mbdts.setMinute(30);
mbdts.setHour(14);
MonthlyByWeekdayTaskScheduler

Schedule a task to run every month (or every specified number of months) on a specified week, weekday, and time (hour: minutes). You can also set the interval property to run the task after a specified number of months.

Example: Schedule a task to run on the last Wednesday of each month at 12:30 a.m.

MonthlyByWeekdayTaskScheduler mbwts =
   new MonthlyByWeekdayTaskScheduler();
mbwts.setOffset(WeekOfMonth.last);
mbwts.setWeekday(DayOfWeek.wednesday);
mbwts.setHour(4);
mbwts.setMinute(30);

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 following code fragment 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.

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);
...