0

I need to run automated tasks every 15. The tasks is for my server (call it server A, Ubuntu 10.04 LAMP) to query for updates to another server (Server B).

I have multiple users to query for, possibly 14 (or more) users. As of now, the scripts are written in PHP. They do the following:

  1. request Server B for updates on users
  2. If Server B says there are updates, then Server A retrieves the updates
  3. In Server A, update DB with the new data for the users in
  4. run calculations in server A
  5. send prompts to users that I received data updates from.

I know cron jobs might be the way to go, but there could be a scenario where I might have a cron job for every user. Is that reasonable? Or should I force it to be one cron job querying data for all my users?

Also, the server I'm querying has a java api that I can use to query it. Which means I could develop a java servlet to do the same. I've had trouble with this approach but I'm looking for feedback if this is the way to go. I'm not familiar with Tomcat and I don't fully understand it yet.

Summary: I need my server to run tasks automatically every 15 mins, the requests data from another server, updates its DB and then send prompts to users. What's are recommended approaches?

Thanks for your help!

4

1 回答 1

0

创建由 cron 触发的单个脚本,该脚本循环遍历每个用户并为每个用户执行所有三个步骤: 伪代码:

query for list of users from local DB;
foreach(users as user){
   check for updates;
   if(updates){
      update db;
      email user;
   }
}

如果您有很多用户或 API 很慢,您可能想要设置一个较长的脚本超时 (ini_set),或者您可以添加一个 TIMESTAMP DB 列“LastUpdateCheck”并更频繁地运行 cron(每 30 秒一次?)但将更新/API 查询限制为每个实例一到两个用户(更新时间最早的用户)

于 2012-04-28T23:01:03.343 回答