简体   繁体   中英

How to set a complex custom crontab in google-app-engine (java)?

I am building an app for which I need to set up cron jobs. What I want to do is to set the specific minutes in a hour where specific crons should run. For instance:

  • Task1 at 1st minute of the hour
  • Task2 on every second minute of the hour
  • Task3 every 2 minute only in the second half of the hour

Building this in the standard Unix cron format is reasonably straightforward, but could not figure out how to do it in the Google-App-Engine.

The documentation does not list any non-trivial examples. Any suggestions on how to do it? Examples would be excellent.

The documentation you linked to seems to indicate that it isn't possible to do what you want using only Cron for Java (unless they have an undocumented feature for it). In particular this doesn't appear to allow for multiple times.

time specifies the time of day, as HH:MM in 24 hour time.

The Python version says the exact same thing.

However, one solution (albeit somewhat more expensive in terms of CPU usage) would be to call a URL every minute, and from the handler for that URL, dispatch out to whatever other calls you need.

In other words, something like:

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/run-scheduled-tasks</url>
    <description>Run all scheduled tasks</description>
    <schedule>every 1 minutes</schedule>
  </cron>
</cronentries>

Then in run-scheduled-tasks, check a database for when each task last run, and if your complex condition for triggering them has occurred since then.

If the documentation is correct you can't get as granular as you are wanting. Doesn't look like they support picking a particular minute of the hour. Or a subset of an hour.

You might have to get creative. Why do you need such specific timing?

This may seem silly. Write three servlet. And schedule them from another UNIX machine on the other part of the world :D. Or even you can write a java app to do it. enjoy

看看Quartz ,看看是否能解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM