| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * app 打包
- */
- namespace App\Jobs;
- use App\Models\Mysql\PackModel;
- use GuzzleHttp\Client;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\Events\JobExceptionOccurred;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class AppPackJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $params = [];
- /**
- * @param array $params
- */
- public function __construct(array $params = [])
- {
- $this->params = $params;
- }
- /**
- *
- * @return void
- */
- public function handle()
- {
- // 延时3秒
- // sleep(3);
- // 超过3次
- logger('AppPackJob-handle-1', ['attempts' => $this->attempts(), 'params' => $this->params]);
- if ($this->attempts() >= 3) {
- $message = '重试次数超过3次!';
- $job = $this->job;
- $message .= ',链接名称' . $job->getConnectionName();
- $message .= ',所属队列名称' . $job->getQueue();
- $message .= ',所属类' . $job->getName();
- // 推送写日志
- logger($message, $this->params);
- // 删除脚本
- $this->delete();
- return;
- }
- $formData = [
- 'timeout' => 30,
- 'headers' => [
- 'X-TOKEN' => env('PACK_TOKEN', 'NrVcnuCUveQbr'),
- 'Content-Type' => 'application/json',
- 'Accept' => 'application/json',
- ],
- 'json' => [
- $this->params,
- ],
- ];
- $url = env('PACK_URL', 'http://dispatch_php.test.wg8.site') . '/api/channel/pack';
- $Client = new Client();
- try {
- $Client->post($url, $formData);
- } catch (\Exception $exception) {
- if (!PackModel::query()->where(
- [
- 'channel_code' => $this->params['channel_code'],
- 'mom_app_uid' => $this->params['mom_app_uid'],
- 'android_or_ios' => $this->params['android_or_ios'],
- 'mom_app_version' => $this->params['mom_app_version'],
- ]
- )->update(['status' => 2])) {
- logger('打包失败!-' . $exception->getMessage(), $this->params);
- }
- return;
- }
- }
- }
|