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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀