Log a failed job into storage.

@param  string $connection
@param  string $queue
@param  string $payload
@return int|null
190130
public function log( $connection, $queue, $payload )
	{
		$failed_at = Carbon::now();

		return $this->getTable()->insertGetId( compact( 'connection', 'queue', 'payload', 'failed_at' ) );
	}
226813
protected function handle(ConnectionInterface $connection, Payload $payload)
    {
        switch ($payload->getEvent()) {
            case ConnectionEvent::SOCKET_AUTH_REQUEST:
                $this->handleAuthentication($connection, $payload);
                break;
            default:
                $this->eventDispatcher->dispatch($payload->getEvent(), new ConnectionEvent($connection, $payload));
                $this->logger->notice(sprintf('Dispatched event: %s', $payload->getEvent()));
        }
    }
1227028
public function fail(\Exception $e)
    {
        $this->stopped();

        $this->setStatus(Job::STATUS_FAILED, $e);

        // For the failed jobs we store a lot more data for debugging
        $packet = $this->getPacket();
        $failed_payload = array_merge(json_decode($this->payload, true), array(
            'worker'    => $packet['worker'],
            'started'   => $packet['started'],
            'finished'  => $packet['finished'],
            'output'    => $packet['output'],
            'exception' => (array)json_decode($packet['exception'], true),
        ));
        $this->redis->zadd(Queue::redisKey($this->queue, 'failed'), time(), json_encode($failed_payload));
        Stats::incr('failed', 1);
        Stats::incr('failed', 1, Queue::redisKey($this->queue, 'stats'));

        Event::fire(Event::JOB_FAILURE, array($this, $e));
    }
264511
protected function raiseFailedJobEvent($connection, Job $job)
	{
		if ($this->events)
		{
			$this->events->fire('flyphp.queue.failed', array($connection, $job));
		}
	}
861828
public function pushRaw($payload, $queueName )
    {
        $this->__handler->rPush($queueName, $payload);

        return Arr::get(json_decode($payload, true), 'id');
    }
1249915
public function pushRaw($payload, $queue = null, array $options = [])
    {
        if ($this->shouldEncrypt) {
            $payload = $this->getEncrypter()->encrypt($payload);
        }

        return $this->iron->postMessage($this->getQueue($queue), $payload, $options)->id;
    }
1365860
private function createFailure(array $payload, Throwable $exception, string $worker, string $queue)
    {
        $this->adapter->createFailure($payload, $exception, $worker, $queue);
    }
844424
protected function createPayload($job, $data = '', $queue = null)
    {
        if (is_object($job)) {
            $payload = json_encode([
                'job' => 'Globalis\PuppetSkilled\Queue\CallQueuedHandler@call',
                'data' => [
                    'commandName' => get_class($job),
                    'command' => serialize(clone $job),
                ],
            ]);
        } else {
            $payload = json_encode($this->createPlainPayload($job, $data));
        }

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new InvalidArgumentException('Unable to create payload: '.json_last_error_msg());
        }

        return $payload;
    }
638556
private function handleErrorResponse(string $connectionName, MessageEnvelopeQueue $queue, Response $response)
    {
        $error = $response->getResponse();
        if (false === is_array($error) or !array_key_exists('identifier', $error)) {
            $queue->traverseWith(function (MessageEnvelope $messageEnvelope) {
                $messageEnvelope->setState(MessageEnvelope::FAILED);
            });
            $queue->clear();
            throw new AppleNotifyFailedException('Message gave an error but no response all messages marked as failed');
        }
        // Get all the items that are sent before or are the failed identifier
        $preIdentifierQueue = $queue->split($error['identifier']);
        // remove the failed identifier from the queue so we can fail it
        $failedMessage = $preIdentifierQueue->remove($error['identifier'])->getOrThrow(new AppleNotifyFailedException('Failed identifier not found: ' . $error['identifier']));
        $failedMessage->setState(MessageEnvelope::FAILED);
        $failedMessage->setResponse($response);
        // every message before the failed one are successful
        $preIdentifierQueue->traverseWith(function (MessageEnvelope $messageEnvelope) {
            $messageEnvelope->setState(MessageEnvelope::SUCCESS);
        });
        // reflush the remainder of the queue these messages have to be send again
        $this->flushQueueItem($connectionName, $queue);
    }
183481
public function markJobFailed(QueuedJob $job, $failureMessage = null) {
		$fields = [
			'failed' => $job->failed + 1,
			'failure_message' => $failureMessage,
		];
		$job = $this->patchEntity($job, $fields);

		return (bool)$this->save($job);
	}
268618
public static function encode($payload, $connection)
    {
        if (empty($connection->websocketType)) {
            $connection->websocketType = self::BINARY_TYPE_BLOB;
        }
        $payload = (string)$payload;
        if (empty($connection->handshakeStep)) {
            self::sendHandshake($connection);
        }
        $mask = 1;
        $mask_key = "\x00\x00\x00\x00";

        $pack = '';
        $length = $length_flag = strlen($payload);
        if (65535 < $length) {
            $pack   = pack('NN', ($length & 0xFFFFFFFF00000000) >> 32, $length & 0x00000000FFFFFFFF);
            $length_flag = 127;
        } else if (125 < $length) {
            $pack   = pack('n*', $length);
            $length_flag = 126;
        }

        $head = ($mask << 7) | $length_flag;
        $head = $connection->websocketType . chr($head) . $pack;

        $frame = $head . $mask_key;
        // append payload to frame:
        for ($i = 0; $i < $length; $i++) {
            $frame .= $payload[$i] ^ $mask_key[$i % 4];
        }
        if ($connection->handshakeStep === 1) {
            // If buffer has already full then discard the current package.
            if (strlen($connection->tmpWebsocketData) > $connection->maxSendBufferSize) {
                if ($connection->onError) {
                    try {
                        call_user_func($connection->onError, $connection, WORKERMAN_SEND_FAIL, 'send buffer full and drop package');
                    } catch (\Exception $e) {
                        Worker::log($e);
                        exit(250);
                    } catch (\Error $e) {
                        Worker::log($e);
                        exit(250);
                    }
                }
                return '';
            }
            $connection->tmpWebsocketData = $connection->tmpWebsocketData . $frame;
            // Check buffer is full.
            if ($connection->maxSendBufferSize <= strlen($connection->tmpWebsocketData)) {
                if ($connection->onBufferFull) {
                    try {
                        call_user_func($connection->onBufferFull, $connection);
                    } catch (\Exception $e) {
                        Worker::log($e);
                        exit(250);
                    } catch (\Error $e) {
                        Worker::log($e);
                        exit(250);
                    }
                }
            }
            return '';
        }
        return $frame;
    }
309242
public static function loadPayload($queue, $payload)
    {
        $payload = json_decode($payload, true);

        if (!is_array($payload) or !count($payload)) {
            throw new \InvalidArgumentException('Supplied $payload must be a json encoded array.');
        }

        return new static($queue, $payload['id'], $payload['class'], $payload['data']);
    }
1216170
protected function pushToDatabase($queue, $payload, $delay = 0, $attempts = 0)
    {
        return $this->db->name($this->table)->insertGetId([
            'queue'        => $this->getQueue($queue),
            'attempts'     => $attempts,
            'reserved_at'  => null,
            'available_at' => $this->availableAt($delay),
            'created_at'   => $this->currentTime(),
            'payload'      => $payload,
        ]);
    }
203714
public function push($job, $data = '', $queue = null)
    {
        return $this->pushRaw($this->createPayload($job, $data, $queue), $queue);
    }
873577
public function pushRaw($payload, $queue = null, array $options = array())
	{
		return $this->pheanstalk->useTube($this->getQueue($queue))->put($payload);
	}
745670
public function reserved($connection, $queue, JobPayload $payload)
    {
        $time = str_replace(',', '.', microtime(true));

        $this->connection()->hmset(
            $payload->id(), [
                'status' => 'reserved',
                'payload' => $payload->value,
                'updated_at' => $time,
                'reserved_at' => $time,
            ]
        );
    }
283820
public function push( $job, $data = '', $queue = null )
	{
		$queueJob = $this->resolveJob( $this->createPayload( $job, $data, $queue ) );

		try
		{
			$this->raiseBeforeJobEvent( $queueJob );

			$queueJob->fire();

			$this->raiseAfterJobEvent( $queueJob );
		}
		catch ( Exception $e )
		{
			$this->raiseExceptionOccurredJobEvent( $queueJob, $e );

			$this->handleFailedJob( $queueJob );

			throw $e;
		}
		catch ( Throwable $e )
		{
			$this->raiseExceptionOccurredJobEvent( $queueJob, $e );

			$this->handleFailedJob( $queueJob );

			throw $e;
		}

		return 0;
	}