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 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程