1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wuzhenke
- * Date: 2019/2/13
- * Time: 9:29
- */
- namespace App\Jobs\Cron;
- use App\Repositories\QueueAutoRefreshRepository;
- use App\Services\Company\JobsService;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\Log;
- class AutoRefreshJobsJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $jobs;
- protected $queueAutoRefresh;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
- /**
- * Execute the job.
- * @param $queueAutoRefreshRepository
- * @param $jobsService
- * @return void
- */
- public function handle(JobsService $jobsService, QueueAutoRefreshRepository $queueAutoRefreshRepository)
- {
- //可以在这个方法里使用依赖注入.
- $time = time();
- $condition[] = ['refreshtime', '<=', $time];
- $condition['type'] = 1;
- $list = $queueAutoRefreshRepository->getRefreshList($condition)->toArray();
- $pid_arr = [];
- foreach ($list as $key => $val) {
- $pid_arr[] = $val['pid'];
- }
- if (!empty($pid_arr)) {
- $result = $jobsService->autoRefreshJobs($pid_arr);
- $ids = implode(',', $pid_arr);
- if ($result) {
- $queueAutoRefreshRepository->deleteWhere($condition);
- } else {
- Log::error("职位ID:".$ids.',智能刷新失败!');
- }
- }
- }
- }
|