How to schedule repeated jobs or tasks from user p

2019-02-15 05:11发布

I'm using Google App Engine and I want like to be able to schedule jobs based users' parameters.

I know this can be done with cron jobs, but looks like it does not allow any flexibility from the user's point of view, but it allows only to schedule predefined jobs.

For example, suppose I have a news app where users can subscribe to different topics: I want the admin to be able to decide when to send a summary email, for instance, every day at 8am, and I want him to be able to edit this.

Is there anything that provides this?

2条回答
何必那么认真
2楼-- · 2019-02-15 05:35

You may want to star Issue 3638: Cron jobs to be scheduled programatically

Meanwhile you can write your own implementation: have a generic cron job running periodically (every 1 minute being the finest resolution) and inside that cron job check user-programmed scheduling data persisted somewhere (in the datastore for example) and, if needed, trigger execution of whatever is needed to be executed, either inlined or by enqueueing a task in some task queue.

It's possible to drive the scheduling resolution even under 1 minute, if needed, see High frequency data refresh with Google App Engine

查看更多
Juvenile、少年°
3楼-- · 2019-02-15 05:37

For my debts tracking app DebtsTracker.io I've implemented it manually.

When a user creates a debt record he can specify due date that is stored in an unindexed DueDate and indexed ReminderDateTime fields.

I have a cron that query records with ReminderDateTime < today and sends notifications. Once notification sent the ReminderDateTime is set to null or far future so it's not picked in next cron run. If user hits Remind me again I am updating the ReminderDateTime to some date in future (user decides when).

If ReminderDateTime is closer then cron interval then I simply create I put a task to queue with appropriate delay.

This works very well and is very cheap to run.

查看更多
登录 后发表回答