uidArr = $uidArr; $this->days = $days; $this->count = $count; } /** * Determine the time at which the job should timeout. * * @return \DateTime */ public function retryUntil() { return now()->addHours(1); } public $tries = 1; public $timeout = 1800; /** * Execute the job. * * @return void */ public function handle() { $toolRep = new ToolRepository(); foreach ($this->uidArr as $uid) { try { $hashArr = $toolRep->generateUniqueInviteHash([], $this->count, $this->count); $data = []; foreach($hashArr as $hash) { $data[] = [ 'inviter' => $uid, 'invitee' => '', 'hash' => $hash, 'valid' => 0, 'expired_at' => Carbon::now()->addDays($this->days), 'created_at' => Carbon::now(), ]; } if (!empty($data)) { Invite::query()->insert($data); } do_log("success add $this->count temporary invite ($this->days days) to $uid"); } catch (\Exception $exception) { do_log("fail add $this->count temporary invite ($this->days days) to $uid: " . $exception->getMessage(), 'error'); } } } /** * Handle a job failure. * * @param \Throwable $exception * @return void */ public function failed(\Throwable $exception) { do_log("failed: " . $exception->getMessage() . $exception->getTraceAsString(), 'error'); } }