1. timemachine
  2. scheduler

Wiki

Clone wiki

scheduler / WebConsole

The TimeMachine Scheduler project comes with a web application, timemachine-web.war, that you may deploy to any Servlet container. It provides a UI to manage your jobs and control your scheduler using a Console shell with web UI. We will cover some of its feature there.

Installation, Deployment, and Configuration

Deploying on Tomcat server

  1. Download Tomcat 6 or higher and unzip it in your file system and call it $TOMCAT_HOME.
  2. Download TimeMachine Scheduler (timemachine-web-x.y.z.war), and copy into $TOMCAT_HOME/webapps
  3. Start Tomcat by running $TOMCAT_HOME/bin/catalina.sh run
  4. Visit browser: http://localhost:8080/timemachine-web-x.y.z

Deploying on JBossAS 7.1.0 server

  1. Download JBossAS 7.1 or higher and unzip it in your file system and call it $JBOSS_HOME.
  2. Download TimeMachine Scheduler (timemachine-web-x.y.z.war), and copy into $JBOSS_HOME/standalone/deployments
  3. Start Tomcat by running $JBOSS_HOME/bin/standalone.sh
  4. Visit browser: http://localhost:8080/timemachine-web-x.y.z

Custom TimeMachine Scheduler Config

The timemachine-web.war application will start with a default in memory scheduler. If you want it to deploy with a custom scheduler configuration upon servlet deploy (not using the web "Config" screen), then you may use this System Properties:

-Dtimemachine.scheduler.configUrl=file:///path/to/scheduler.properties

UI Screens

Jobs Screen

The home page of the web application should be on the "Jobs" listing page. Here you will see all the job definitions in your scheduler. There are two sections, the ones on top are job definitions that has at least one Schedule associated (each Schedule is a "job" on its own row of listing.). The bottom section will list any job definitions that has no Schedule associated.

When a "Schedule/job" is scheduled, this page will show all the fields that you most interested, such as the Schedule's id/name, the state, the nextRun time, JobTask class, and also some actions available per that specific "Schedule/job". You may Run, Pause/Resume, or even delete that Schedule. If you click "Run", it will create a new Schedule that only repeat one time and start executing the JobTask immediately.

On the Jobs screen, each scheduled job's name/id will is a link into a detail display page. In there you will see all the schedule information, include a link to preview future run times.

Also on the Jobs screen, each job def's id is a link into a detail display page. In this detail page, it will query all the associated Schedules for this job definition.

Histories Screen

The TimeMachine Scheduler has a feature to allow you to record all scheduler events and they will be display here. The scheduler default configuration will NOT enable this though. So if you want these data, please add these lines to your scheduler config to enable this:

# Scheduler Event History Service (604800000 ms = 7 days)
timemachine.scheduler.eventHistory.class = timemachine.scheduler.service.EventHistoryService
timemachine.scheduler.eventHistory.removeInterval = 604800000

If you enabled these, then scheduler events such as when it start or stop, or any job run information will be recorded and display here. If you do not want too much histories, then simply set the "removeInterval" to small value.

Services Screen

This page shows you all the system and user services that are running in the scheduler.

Config Screen

This page provides a form to let you edit the scheduler configuration settings. You may edit and click Update button to save it. Updating config will destroy the current scheduler, and then re-create a new scheduler instance. This means that if you are using a MemoryDataStore, your job data will be lost upon Updating config!

If you forgot or want to reset things back to default config, there is a link on page to show you that content.

Console Screen

This is the web Console shell screen that let you manage and control the scheduler using the Groovy scripting. There is already a implicit variable named "scheduler" that you may use in script console, and through it, you will have full control to the scheduler. The console provides a full access to not only scheduler, but to your entire JVM and OS as well! This is powerful, yet dangerous if you are not careful. Due to this, you almost want to secure this web app, and only intend to be use as admin tool. Deploy this web application to public internet is not recommended.

Health Check

The web application also provides a health check url /health that you may use to poll and check the status of the scheduler. It will return you a small xml packet that show scheduler and server information.

Here is an sample output:

<?xml version="1.0" encoding="UTF-8"?>
<health>
	<appName>timemachine-scheduler</appName>
	<schedulerId>1</schedulerId>
	<schedulerNodeId>1</schedulerNodeId>
	<schedulerStarted>true</schedulerStarted>
	<schedulerVersion>1.2.0-SNAPSHOT.071420122255</schedulerVersion>
	<serverInfo>JBoss Web/7.0.10.Final</serverInfo>
	<serverTime>1342359696477</serverTime>
	<webappUpTime>10:40:11.554</webappUpTime>
</health>

Creating Jobs using web UI

Create New Jobs

Using JobLoaderService

Go into Console screen, and type the following groovy script in the shell

// Create an hourly job.
import timemachine.scheduler.*
import timemachine.scheduler.jobtask.*
jobDef = new JobDef()
jobDef.setJobTaskClass(LoggerJobTask.class)
jobDef.addSchedule(Schedules.hourly(1).setName('sample-job'))
scheduler.schedule(jobDef)
webout.println("Done: $jobDef has been scheduled.")

You may click on the "sample" link in the web application to see more.

Using JobLoaderService

Go into Console screen, and type the following in the shell

import timemachine.scheduler.userservice.*
JobLoaderService.load(scheduler, '/path/to/scheduler-job-loaders.properties')

See ReferenceManual on how to configure JobLoaderService.

Delete Jobs

Go into Console screen, and type the following groovy script in the shell

Delete a particular Scheduled Job

// Delete a Schedule by name
import timemachine.scheduler.*
schedules = scheduler.findSchedules('job1-schedule4')
schedule = schedules[0]
scheduler.unschedule(schedule)
webout.println("Done: $schedule has been removed.")

Delete All Schedules and Job Definitions

// Delete all jobs
import timemachine.scheduler.*
jobDefs = scheduler.findJobDefs()
jobDefs.each{ jobDef -> scheduler.unschedule(jobDef) }
webout.println("Done: $jobDefs.size JobDef has been removed.")

Reporting

Go into Console screen, and type the following groovy script in the shell

// Show top most run counts
schedules = scheduler.findSchedules().sort{s1,s2->s2.runCount <=> s1.runCount}
schedules.each{ webout.println(it.id+' '+it.runCount+' '+it.missedRunCount) }
webout.println("Done: ${schedules.size()} schedules.")

// Show top missed run counts
schedules = scheduler.findSchedules().grep{s->if(s.missedRunCount > 0) s }
schedules.sort{s1,s2->s2.missedRunCount <=> s1.missedRunCount}
schedules.each{ webout.println(it.id+' '+it.missedRunCount+' '+it.runCount) }
webout.println("Done: ${schedules.size()} schedules.")

// Show all schedules using the system sorter
import timemachine.scheduler.*
import timemachine.scheduler.support.*
schedules = scheduler.findSchedules()
Collections.sort(schedules, new ScheduleComparator())
schedules.each{ s ->
  webout.println(s.toString() + ", nextRun: " + s.getNextRun() + ", state: " + s.getState() + ", startTime: " + s.getStartTime())
}
webout.println("Done: ${schedules.size()} schedules.")

Updated