<?xml version="1.0"?>
<oddjob>
	<!-- =============================================
	FTP get a span file from the CME website.
	============================================== -->
	<sequential name="Scheduler Demo">
		<!-- =============================================
		Variables for the clock an holidays.
		============================================== -->
		<variables id="vars" name="Set clocks and calendars">
			<!-- use a Eastern Standard Time time zone so this
				example should run without modifying the schedule
				whichever time zone the local machine is in. -->
			<clock name="us-clock" timeZone="EST"/>
			<!-- and Hong Kong -->
			<clock name="hk-clock" timeZone="GMT+08"/>
			<!-- These are the none working days -->
			<schedule name="holidays">
				<dayofweek from="sat" to="sun"/>
				<date on="25-dec-05"/>
			</schedule>
		</variables>
		<!-- =============================================
		The scheduler And jobs.
		============================================== -->
		<parallel name="A Scheduler and Jobs">
		<!-- =============================================
		The scheduler job.
		============================================== -->
			<scheduler name="The Scheduler" id="sched">
				<schedules>
					<!-- =============================================
					Kansas Schedule.
					============================================== -->
					<ojschedule name="KCB Schedule"
						job="${kcb-trans}"
						clock="${vars.us-clock}">
						<!-- The regular schedule allows for holidays -->
						<schedule>
							<broken breaks="${vars.holidays}">
								<schedule>
									<time from="19:00" to="17:00"/>
								</schedule>
							</broken>
						</schedule>
						<!-- If the download failed we try re running
						for two attempts after 15 minuets. The after
						is because interval on it's own would run
						immediately. -->
						<retry>
							<count count="10">
								<interval interval="00:15"/>
							</count>
						</retry>
					</ojschedule>
					<!-- =============================================
					Hong Kong Schedule
					============================================== -->
					<ojschedule name="HKF Schedule"
						job="${hkf-trans}"
						clock="${vars.hk-clock}">
						<!-- The regular schedule allows for holidays -->
						<schedule>
							<broken breaks="${vars.holidays}">
								<schedule>
									<time from="19:00" to="17:00"/>
								</schedule>
							</broken>
						</schedule>
						<!-- If the download failed we try re running
						for two attempts after 15 minuets. The after
						is because interval on it's own would run
						immediately. -->
						<retry>
							<count count="10">
								<interval interval="00:15"/>
							</count>
						</retry>
					</ojschedule>
					<trigger job="${exception}" name="KCB Exception">
						<trigger on="${sched.lookup(KCB Schedule)}"
							state="exception"/>
					</trigger>
					<trigger job="${exception}" name="HKF Exception">
						<trigger on="${sched.lookup(HKF Schedule)}"
							state="exception"/>
					</trigger>
				</schedules>
			</scheduler>
			<folder name="Some Jobs to Schedule.">
				<!-- =============================================
				The sequence that does the transfer.
				============================================== -->
				<sequential name="KCB Transfer Sequence" id="kcb-trans">
					<!-- =============================================
					Format the date as it's required in the file name.
					============================================== -->
					<variables id="kcb-vars" name="Format Date">
						<format name="filedate" format="yyyyMMdd" 
							date="${sched.lookup(KCB Schedule).scheduleDate}"/>
						<value name="filename" 
							value="kcb.${kcb-vars.filedate}.s.pa2.zip"/>
					</variables>
					<!-- =============================================
					FTP the file.
					============================================== -->
					<ant name="FTP file back">
						<ftp server="ftp.cme.com" userid="anonymous" 
							password="anonymous" remotedir="pub/span/data/kcb" 
							action="get" passive="yes">
							<fileset dir=".">
								<include name="${kcb-vars.filename}"/>
							</fileset>
						</ftp>
					</ant>
					<!-- =============================================
					Check we got the file, Ant ftp doesn't care.
					============================================== -->
					<exists name="Check File" file="${kcb-vars.filename}"/>
				</sequential>
				<!-- =============================================
				The sequence that does the transfer.
				============================================== -->
				<sequential name="HKF Transfer Sequence" id="hkf-trans">
				<!-- =============================================
				Format the date as it's required in the file name.
				============================================== -->
					<variables id="hkf-vars" name="Format Date">
						<format name="filedate" format="MMdd" 
							date="${sched.lookup(HKF Schedule).scheduleDate}"/>
						<value name="filename" 
							value="hkex${hkf-vars.filedate}s.zip"/>
					</variables>
					<!-- =============================================
					FTP the file.
					============================================== -->
					<ant name="FTP file back">
						<ftp server="ftp.cme.com" userid="anonymous" 
							password="anonymous" remotedir="pub/span/data/hkf" 
							action="get" passive="yes">
							<fileset dir=".">
								<include name="${hkf-vars.filename}"/>
							</fileset>
						</ftp>
					</ant>
					<!-- =============================================
					Check we got the file, Ant ftp doesn't care.
					============================================== -->
					<exists name="Check File" file="${hkf-vars.filename}"/>
				</sequential>
				<!-- =============================================
				If a schedulable job throws an exception this job
				will be executed which sends a mail. Our schedule
				will throw an exception once the retries have run.  
				============================================== -->
				<ant id="exception" name="Send alert mail">
					<mail from="oddjob@somewhere.com" 
						tolist="support@somewhere" mailhost="your.smtp.host" 
						subject="FTP download failed" 
						message="FTP download failed."/>
				</ant>
			</folder>
		</parallel>
	</sequential>
</oddjob>