Elad Benda2 Elad Benda2 - 1 year ago 61
Java Question

can i create a cron job with no scheduling

I want to set a cron job that will be with run only by app-engine ui triggering (pressing a button on app-engine)

How can i set the cron.xml to include no scheduling?

<?xml version="1.0" encoding="UTF-8"?>
<description>find buddies to all users</description>

Answer Source

AFAIK this is not possible.

I see 2 possible alternatives, based on a flag controlled by the GUI, indicating if the "cron" job should run or not:

  • have a regular cron just check if the flag is set: do the job if it is set and exit immediately if it's not


  • use the deferred library: when setting the flag also trigger a deferred task, which, in addition to executing the job also keeps triggering itself as long as the flag is set; the deferred library also allows repeating the task at sub-second intervals, which is not possible with regular cron (if that's of interest to you).


The deferred library has at least one drawback: can't access the request handler inside the deferred function. But the deferred functionality is also available in the Task Queues (mentioned by @jirungaray's answer) - using the optional countdown or eta arguments to taskqueue.add():

  • countdown -- Time in seconds into the future that this task should run or be leased. Defaults to zero. Do not specify this argument if you specified an eta.

  • eta -- A datetime.datetime that specifies the absolute earliest time at which the task should run. You cannot specify this argument if the countdown argument is specified. This argument can be time zone-aware or time zone-naive, or set to a time in the past. If the argument is set to None, the default value is now. For pull tasks, no worker can lease the task before the time indicated by the eta argument.

This makes task queues preferable to the deferred library.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download