duanhong4274 2017-05-08 12:01
浏览 88
已采纳

亚马逊MWS的Laravel后台工作最佳实践

I'm working with external feeding API "Amazon mws" which I get all products for specific seller. Now let me say if I want to refresh these products by two methods: Automatically and manualy, the automatic approach would be refreshing this store every 12 hours for example, and the manual approach is to let the seller manually click a refresh link and further to display progress bar until this job is done.

So, now how can I manage to make these two methods ? I'm totally confused between jobs, queues and task scheduling, whether to use beanstalkd or redis ?

I just want somebody to direct me how to manage all of that and best practice for this situation... Thanks Artisans :)

  • 写回答

2条回答 默认 最新

  • duanben1324 2017-05-22 09:18
    关注

    For the automatic refresh you can run a task scheduler (system to system) the user is not involved, it is a perfect case for scheduling a task.

    Whereas the refresh button, would be a job, but take this into account that a job can be queued or not queued, by either implementing shouldQueue or not. If you will like this job to be done in the background, you can queue that job to be done async.

    Then set up an event that fires when the job has completed, or when the database is updated , and you can broadcast a notification to the user informing him her or team that the update has been completed.

    So lets take it step by step, you can make jobs with artisan command this job you can dispatch from your controller.

    Write your business logic in the job and implement shouldQueue. Job does not need a return statement. Then create the queue with artisan command this will create the queue table, and change queue driver in env to database (you can get quite a long way with database queue so you dont have to use beanstalkd, and it is good way of practice queues, you should then queue:listen ! Just a note when U use queue listen the listen will keep running untill you close the terminal, then when opening a terminal before running listen queue:restart.

    Create the event you want with artisan and on your model listen for the event updated, when the updated is complete the event will fire.

    Create the notification with artisan command and on the event listener, event notify. the notification you can customize what you want to notify.

    You will need to broadcast this notification and for that you will need to create an account with pusher, and broadcast the event.

    The laravel documentation covers it all but it is difficult to know where to start.

    To broadcast with pusher install pusher and laravel echo then in jour event you broadcast to and a channel on your web routes will be created channel, there are some other settings and configs, just a tip to thest the broadcast and to receive something back on your front end just to test. broadcast to channel not private channel just a bit easier setting things up from there if it works do whatever you want.

    Hope it helps. @gustav1105 from laracasts

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win11笔记本系统出了问题
  • ¥20 找驱动QTR2774-SU-IBM版本驱动
  • ¥15 NeRF的代码复现以及人工智能入门
  • ¥15 centos如何做一个可以让ikuai连接的openvpn
  • ¥15 Protege 中的Entities下面的界面删除了如何复原
  • ¥15 scrapy爬虫求帮
  • ¥15 imageEnView绘图问题
  • ¥15 关于#python#的问题:您好可以加您一下联系方式吗,在复现的时候确实有点问题难以解决
  • ¥15 联想电脑重装系统时无法发现硬盘
  • ¥15 MATLAB与UR10e实体机械臂建立通讯