AutoRefreshJobsJob.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2019/2/13
  6. * Time: 9:29
  7. */
  8. namespace App\Jobs\Cron;
  9. use App\Repositories\QueueAutoRefreshRepository;
  10. use App\Services\Company\JobsService;
  11. use Illuminate\Bus\Queueable;
  12. use Illuminate\Contracts\Queue\ShouldQueue;
  13. use Illuminate\Foundation\Bus\Dispatchable;
  14. use Illuminate\Queue\InteractsWithQueue;
  15. use Illuminate\Queue\SerializesModels;
  16. use Illuminate\Support\Facades\Log;
  17. class AutoRefreshJobsJob implements ShouldQueue
  18. {
  19. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  20. protected $jobs;
  21. protected $queueAutoRefresh;
  22. /**
  23. * Create a new job instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. //
  30. }
  31. /**
  32. * Execute the job.
  33. * @param $queueAutoRefreshRepository
  34. * @param $jobsService
  35. * @return void
  36. */
  37. public function handle(JobsService $jobsService, QueueAutoRefreshRepository $queueAutoRefreshRepository)
  38. {
  39. //可以在这个方法里使用依赖注入.
  40. $time = time();
  41. $condition[] = ['refreshtime', '<=', $time];
  42. $condition['type'] = 1;
  43. $list = $queueAutoRefreshRepository->getRefreshList($condition)->toArray();
  44. $pid_arr = [];
  45. foreach ($list as $key => $val) {
  46. $pid_arr[] = $val['pid'];
  47. }
  48. if (!empty($pid_arr)) {
  49. $result = $jobsService->autoRefreshJobs($pid_arr);
  50. $ids = implode(',', $pid_arr);
  51. if ($result) {
  52. $queueAutoRefreshRepository->deleteWhere($condition);
  53. } else {
  54. Log::error("职位ID:".$ids.',智能刷新失败!');
  55. }
  56. }
  57. }
  58. }