问题
In GAE we can add cron job manually by editing the cron.xml file
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/cron/addCount/1</url>
<description>Add count + 1 every 1 minutes</description>
<schedule>every 1 minutes</schedule>
</cron>
</cronentries>
Is there any way that I can make a user interface and create/update/delete as many cron jobs on the fly.That means after I deploy to GAE , I should be able to update the cron.xml ? Or is there a work around so that I can create cron jobs on the fly ?
回答1:
No this is not possible.
You should just save this schedule data to datastore, then run cron every minute and check if there is something you need to do. Basically you'd be doing your own simple scheduler.
回答2:
You can use push queues to create and run tasks.
回答3:
Update for 2019
Google Cloud Scheduler has been created for this specific purpose. It essentially runs managed cron jobs under the hood (including automatic retries for failed jobs).
Cloud Scheduler REST API
RPC reference
(I would also recommend considering the suggestion by @Peter Knego to create your own scheduler based on DataStore entries, as this is potentially more flexible and lower cost than using Google Cloud Scheduler, if you need to create a lot of scheduled tasks or complex rules around tasks scheduling)
Another potential option (depending on your use case) is Google Cloud Tasks. This is a newer replacement for Push Queues, introduced recently by Google, and there is an API for creating new tasks programatically. Cloud Tasks essentially centralises Push Queue management in Google Cloud (although you can continue using Push Queues with the older API, for existing applications).
I wouldn't generally recommend this as a way of achieving the type of dynamic task that the OP is suggesting, as Push Queues are really intended for message processing, particularly with high-volume messaging (see my notes on 'Scheduled Tasks vs Push Queues').
If Push Queues are a suitable option for your use case, the quickstart guide gives examples of Google Cloud Tasks API usage. Examples for Java, Python, C# and other languages are available at the link below):
https://cloud.google.com/tasks/docs/quickstart-appengine
Scheduled Tasks vs Push Queues
- Google Cloud Scheduler = scheduled tasks
- Google Cloud Tasks = push queues (message queuing)
You may be asking how you decide between using Scheduled Tasks (e.g. Google Cloud Scheduler) and Push Queues (e.g. using Google Cloud Tasks).
Scheduled Tasks are typically for longer running or more intensive processing tasks, or for any tasks where it's important to predict and control when a task will run. For example, aggregation or processing of large datasets. or bulk processing of data. You can think of cron jobs as the schedule definition/config for a scheduled task.
Push Queues are essentially a form of persistent message queuing, and are generally more appropriate for systems handling large traffic volumes e.g. a busy e-commerce website, where the requests or 'messages' from users need to be decoupled from the system that processes them (e.g. the web back-end or database server). This architecture is used in high volume systems to queue messages for processing and to prioritise the reliability of processing requests in preference to immediate processing against a service back-end. Push queues are more closely related to pub/sub architectures and technologies, like Google Cloud Pub/Sub
来源:https://stackoverflow.com/questions/12116799/adding-dynamic-cron-jobs-to-gae