海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4 KiB

4 years ago
4 years ago
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Agent;
  4. use App\Models\MiniProgramTemplate;
  5. use App\Service\UploadMiniProgram;
  6. use Exception;
  7. use GuzzleHttp\Exception\GuzzleException;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. class UploadMiniProgramQueue implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private int $template_id; //小程序模板ID
  17. private int $agent_id;
  18. /**
  19. * 任务可尝试的次数
  20. * @var int
  21. */
  22. public $tries = 3;
  23. /**
  24. * 任务失败前允许的最大异常数
  25. * @var int
  26. */
  27. public $maxExceptions = 3;
  28. /**
  29. * Create a new job instance.
  30. *
  31. * @param int $template_id 小程序模板ID
  32. * @param int $agent_id 代理商ID
  33. */
  34. public function __construct(int $template_id, int $agent_id)
  35. {
  36. $this->template_id = $template_id;
  37. $this->agent_id = $agent_id;
  38. }
  39. /**
  40. * Execute the job.
  41. *
  42. * @return void
  43. * @throws Exception
  44. */
  45. public function handle()
  46. {
  47. $agent = Agent::find($this->agent_id);
  48. $template = MiniProgramTemplate::find($this->template_id);
  49. if (!$agent || !$template) return;
  50. try {
  51. new UploadMiniProgram($agent, $template);
  52. } catch (GuzzleException | \Exception $e) {
  53. throw new Exception($agent->id . '-' . $agent->appid . $e->getMessage());
  54. }
  55. }
  56. }