A potential problem with cron services in Beanstalk is that this scheduled command can be called by more than one service if the application runs on more than one instance. Coordination between Tomcat executable instances is required to ensure that only one job is running and that if one of them dies, the cron service will not be interrupted.
How do I implement this:
- The "config file" cron package is set using WAR. This file should contain frequencies and URLs (since each actual cron is just a call to a specific URL, as AE does)
- Use one database table to maintain coordination. This requires at least two columns.
tomcat cron, WAR , . , "" , , , "".
query(SELECT last_execution_time FROM crontable WHERE command = ?)if(NOW() - last_execution_time < reasonable window) skip;query(UPDATE crontable SET last_execution_time = NOW() WHERE command = ? AND last_execution_time = ?)if(number of rows updated == 0) skip;run task()
, last_execution_time WHERE, , - , SELECT UPDATE, , , .