douqian1296 2016-08-31 05:20
浏览 41
已采纳

使用cron作业处理大型数据库以进行远程API连接

I am newbie in Laravel and building a small project for practice.

There is one registration form and up to 100 registration done a day approx.

It return me status->pending of user.

Now my question come here that, php execution time for connection with remote Api is 30 second as per my knowledge.

Then, how can I handle the cron job in such a condition where I need to call remote api for receiving the data for every user status if it becomes "accepted" or "rejected" or still in "pending"

I am struggling with this condition and my database structure like

userId - status - created_at - updated_at

I need to call it after 20 hours if possible for all user or every 4 hours if we cannot call them at once.

What will be the best practise to do it?

  • 写回答

1条回答 默认 最新

  • dongtui8593 2016-08-31 06:40
    关注

    For long-running tasks, two options come to my mind:

    Task Queues

    Use an asynchronous task queue. They are designed for long-running tasks. Schedule one job for each newly registered user. Be sure to set the timeout longer than your estimated 30s. Pass the user instance to the constructor of the job and store it to an instance variable. From within the handler, just update the record directly.

    Callback

    Implement a callback via http. This requires control over the remote api. When calling the remote api, you would submit a callback url, such as https://local-app.domain/callbacks/finished-check-user/223 where 223 is the id of the user. The remote api would send a http request to the given url after it's finished processing. In your local app, have a controller handle the request, fetch the user by its id and update it with the data received from the remote api in the request body. Don't forget to make sure the request is authentic.

    Does this help?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员