Professional Documents
Culture Documents
Cron Job in Springs
Cron Job in Springs
About cron.xml
Ac r o n . x m lfile in the W E B I N Fdirectory of your application (alongside a p p e n g i n e w e b . x m l ) controls cron for your Java application. The following is an example c r o n . x m lfile: < ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " U T F 8 " ? > < c r o n e n t r i e s > < c r o n > < u r l > / r e c a c h e < / u r l > < d e s c r i p t i o n > R e p o p u l a t et h ec a c h ee v e r y2m i n u t e s < / d e s c r i p t i o n > < s c h e d u l e > e v e r y2m i n u t e s < / s c h e d u l e > < / c r o n > < c r o n > < u r l > / w e e k l y r e p o r t < / u r l > < d e s c r i p t i o n > M a i lo u taw e e k l yr e p o r t < / d e s c r i p t i o n > < s c h e d u l e > e v e r ym o n d a y0 8 : 3 0 < / s c h e d u l e > < t i m e z o n e > A m e r i c a / N e w _ Y o r k < / t i m e z o n e > < / c r o n > < c r o n > < u r l > / w e e k l y r e p o r t < / u r l > < d e s c r i p t i o n > M a i lo u taw e e k l yr e p o r t < / d e s c r i p t i o n > < s c h e d u l e > e v e r ym o n d a y0 8 : 3 0 < / s c h e d u l e > < t i m e z o n e > A m e r i c a / N e w _ Y o r k < / t i m e z o n e > < t a r g e t > v e r s i o n 2 < / t a r g e t > < / c r o n > < / c r o n e n t r i e s > For an XSD describing the format, check the file d o c s / c r o n . x s din the SDK. Ac r o n . x m lfile consists of a number of job definitions. A job definition must have a < u r l >and a < s c h e d u l e > . You can also optionally specify a < d e s c r i p t i o n > , < t i m e z o n e > , and a < t a r g e t > . The description is visible in the Admin Console. The u r lurl field is just a URL in your application. If the u r lelement contains the special XML characters & ,< ,> ,' , or " , you should escape them. The format of the s c h e d u l efield is covered more in The Schedule Format. The t i m e z o n eshould be the name of a standard zoneinfo time zone name. If you don't specify a timezone, jobs run in UTC (also known as GMT). The t a r g e tspecifies the version of your application on which to invoke the URL. See About appengine-web.xml for more information about application versions.
https://developers.google.com/appengine/docs/java/config/cron
1/3
1/10/14
e v e r y1 2h o u r s e v e r y5m i n u t e sf r o m1 0 : 0 0t o1 4 : 0 0 2 n d , t h i r dm o n , w e d , t h uo fm a r c h1 7 : 0 0 e v e r ym o n d a y0 9 : 0 0 1 s tm o n d a yo fs e p , o c t , n o v1 7 : 0 0 e v e r yd a y0 0 : 0 0
If you don't need to run a recurring job at a specific time, but instead only need to run it at regular intervals, use the form: e v e r yN( h o u r s | m i n s | m i n u t e s )[ " f r o m "( t i m e )" t o "( t i m e ) ] The brackets are for illustration only, and quotes indicate a literal. N specifies a number. hours or minutes (you can also use mins ) specifies the unit of time. time specifies a time of day, as HH:MM in 24 hour time. By default, an interval schedule starts the next interval after the last job has completed. If a from...to clause is specified, however, the jobs are scheduled at regular intervals independent of when the last job completed. For example: e v e r y2h o u r sf r o m1 0 : 0 0t o1 4 : 0 0 This schedule runs the job three times per day at 10:00, 12:00, and 14:00, regardless of how long it takes to complete. You can use the literal "synchronized" as a synonym for from 00:00 to 23:59: e v e r y2h o u r ss y n c h r o n i z e d If you want more specific timing, you can specify the schedule as: ( " e v e r y " | o r d i n a l )( d a y s )[ " o f "( m o n t h s p e c ) ]( t i m e ) Where: ordinal specifies a comma separated list of "1st", "first" and so forth (both forms are ok) days specifies a comma separated list of days of the week (for example, "mon", "tuesday", with both short and long forms being accepted); "every day" is equivalent to "every mon,tue,wed,thu,fri,sat,sun" monthspec specifies a comma separated list of month names (for example, "jan", "march", "sep"). If omitted, implies every month. You can also say "month" to mean every month, as in "1,8,15,22 of month 09:00". time specifies the time of day, as HH:MM in 24 hour time.
Note: While cron jobs can use URL paths restricted with < r o l e n a m e > a d m i n < / r o l e n a m e > , they cannot use URL paths restricted with < r o l e n a m e > * < / r o l e n a m e > . For more on the format of w e b . x m l , see the documentation on the deployment descriptor. To test a cron job, sign in as an administrator and visit the URL of the handler in your browser. Requests from the Cron Service will also contain a HTTP header:
https://developers.google.com/appengine/docs/java/config/cron
2/3
1/10/14
X A p p E n g i n e C r o n :t r u e
The X A p p E n g i n e C r o nheader is set internally by Google App Engine. If your request handler finds this header it can trust that the request is a cron request. If the header is present in an external user request to your app, it is stripped. The exception being requests from logged in administrators of the application, who are allowed to set the header for testing purposes. Google App Engine issues Cron requests from the IP address 0.1.0.1.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Last updated November 19, 2013.
https://developers.google.com/appengine/docs/java/config/cron
3/3