Extract the failed job name from payload.

@param  string  $payload
@return string|null
498260
private function extractJobName($payload)
	{
		$payload = json_decode($payload, true);

		if ($payload && (! isset($payload['data']['command']))) {
			return Arr::get($payload, 'job');
		}

		if ($payload && isset($payload['data']['command'])) {
			preg_match('/"([^"]+)"/', $payload['data']['command'], $matches);

			if (isset($matches[1])) {
				return $matches[1];
			} else {
				return Arr::get($payload, 'job');
			}
		}
	}
223336
function parseRequest( $payload )
    {
        if ( isset( $_SERVER['HTTP_SOAPACTION'] ) )
        {
            // this list of replacements built by testing different clients...
            // we should really parse the xml instead!
            $soapaction = trim( $_SERVER['HTTP_SOAPACTION'], '"' );
            $soapaction = preg_replace( array( '#^urn:#', '#^/*#', '#Action$#' ), '', $soapaction );
            $request = new ggPhpSOAPRequest( $soapaction );
            // this call is used to store the raw  xml in the request object
            $request->decodeStream( $payload );
            $request->setSoapVersion( 1 );
            return $request;
        }
        else
        {
            /*$request = new ggPhpSOAPRequest( '...' );
            $request->decodeStream( $payload );
            $request->setSoapVersion( 2 );
            return $request;*/
            return false;
        }
    }
1027003
protected function parseFailedJob(array $failed)
    {
        $row = array_values(Arr::except($failed, ['payload', 'exception']));

        array_splice($row, 3, 0, $this->extractJobName($failed['payload']));

        return $row;
    }
124754
public function process($payload)
    {
        foreach ($this->stages as $stage) {
            $payload = call_user_func($stage, $payload);
        }
        return $payload;
    }
1283516
protected function resolveAndHandle(array $payload)
    {
        list($class, $method) = Str::parseCallback($payload['job'], 'handle');

        $this->instance = $this->resolve($class);

        call_user_func(array($this->instance, $method), $this, $payload['data']);
    }
799366
public function parse(string $payload): ResultSpec
    {
        $data = @json_decode($payload, true);

        if (!is_array($data)) {
            throw new BaseClientException('Parse error', JsonRpcException::PARSE_ERROR);
        }

        $units = [];

        if ($this->isSingleResponse($data)) {
            $units[] = $this->decodeResult($data);
            return new ResultSpec($units, true);
        }

        /** @var array $data */
        foreach ($data as $response) {
            $units[] = $this->decodeResult($response);
        }

        return new ResultSpec($units, false);
    }
1169506
protected function failed($e)
    {
        $payload = $this->payload();

        [$class, $method] = JobName::parse($payload['job']);

        if (method_exists($this->instance = $this->resolve($class), 'failed')) {
            $this->instance->failed($payload['data'], $e);
        }
    }
901994
protected function failJob($job, Exception $exception)
    {
        if ($job instanceof JobInterface) {
            $payload = $job->getPayload();
            $queue   = $job->getQueue();
        } else {
            $payload = $job;
            $queue   = isset($job['queue']) ? $job['queue'] : null;
        }

        $id = isset($job['id']) ? $job['id'] : null;

        if ($id) {
            try {
                $status = $this->resque->getStatusFactory()->forId($id);
                $status->update(Status::STATUS_FAILED);
            } catch (JobIdException $e) {
                $this->logger->warning($e);
            }
        } // else no status to update

        $this->resque->getFailureBackend()->receiveFailure(
            $payload,
            $exception,
            $this,
            $queue
        );

        $this->getResque()->getStatistic('failed')->incr();
        $this->getStatistic('failed')->incr();
    }
603025
public function parse($payload)
    {
        if ($payload) {
            $json = json_decode(trim($payload), true);
            if ( ! $json) {
                throw new ParserException('Failed To Parse JSON');
            }
            return $json;
        }

        return [];
    }
1010969
public function determineTypeAndMessage($payload)
    {

        switch($payload['responsecode']) {
            case "MT001":
                $payload['message'] = "DOI ".$payload['doi']." was successfully minted.";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT002":
                $payload['message'] = "DOI ".$payload['doi']." was successfully updated.";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT003":
                $payload['message'] = "DOI ".$payload['doi']." was successfully deactivated.";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT004":
                $payload['message'] = "DOI ".$payload['doi']." was successfully activated.";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT005":
                $payload['message'] = "The ANDS Cite My Data service is currently unavailable. Please try again at a later time. If you continue to experience problems please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
            case "MT006":
                $payload['message'] = "The metadata you have provided to mint a new DOI has failed the schema validation. 
			Metadata is validated against the latest version of the DataCite Metadata Schema. 
			For information about the schema and the latest version supported, 
			please visit the ANDS website http://ands.org.au. 
			Detailed information about the validation errors can be found below.";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
            case "MT007":
                $payload['message'] = "The metadata you have provided to update DOI ".$payload['doi']." has failed the schema validation. 
			Metadata is validated against the DataCite Metadata Schema.
			For information about the schema and the latest version supported, 
			please visit the ANDS website http://ands.org.au. 
			Detailed information about the validation errors can be found below.";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
            case "MT008":
                $payload['message'] = "You do not appear to be the owner of DOI ".$payload['doi'].". If you believe this to be incorrect please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 415;
                break;
            case "MT009":
                $payload['message'] = "You are not authorised to use this service. For more information or to request access to the service please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 415;
                break;
            case "MT010":
                $payload['message'] = "There has been an unexpected error processing your doi request. For more information please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
            case "MT011":
                $payload['message'] = "DOI ".$payload['doi']." does not exist in the ANDS Cite My Data service.";
                $payload['type'] = "failure";
                $payload['code'] = 200;
                break;
            case "MT012":
                $payload['message'] = "No metadata exists in the Cite My Data service for DOI ".$payload['doi'];
                $payload['type'] = "failure";
                $payload['code'] = 200;
                break;
            case "MT013":
                $payload['message'] = $payload['verbosemessage'];
                $payload['verbosemessage'] = strlen($payload['verbosemessage']) . " bytes";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT014":
                $payload['message'] = "The provided URL does not belong to any of your registered top level domains. If you would like to add additional domains to your account please contact services@ands.org.au. ";
                $payload['type'] = "failure";
                $payload['code'] = 200;
                break;
            case "MT015":
                $payload['message'] = "DOI ".$payload['doi']." was successfully reserved.";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT016":
                $payload['message'] = "Reserved DOI ".$payload['doi']." was successfully minted. ";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT017":
                $payload['message'] = "The DOI ".$payload['doi']." provided to mint/reserve a DOI does not match the DOI prefix allocated to your account. For more information, please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 200;
                break;
            case "MT018":
                $payload['message'] = "No metadata exists for the requested DOI. Metadata must be registered before the DOI can be minted.";
                $payload['type'] = 'failure';
                $payload['code'] = 400;
                break;
            case "MT019":
                $payload['message'] = $payload['verbosemessage'];
                $payload['type'] = 'success';
                $payload['code'] = 200;
                break;
            case "MT090":
                // Success response for status pings (verbose message should indicate ms turnaround time)
                $payload['message'] = "The rocket is ready to blast off -- all systems are go!";
                $payload['type'] = "success";
                $payload['code'] = 200;
                break;
            case "MT091":
                // Failure response for status pings
                $payload['message'] = "Uh oh! DOI Service unavailable (unable to process upstream DOI request). Please try again in a few moments. ";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
            default:
                $payload['message'] = "There has been an unidentified error processing your doi request. For more information please contact services@ands.org.au.";
                $payload['type'] = "failure";
                $payload['code'] = 500;
                break;
        }

        return $payload;
    }
1131071
public function failError()
    {
        if (
            ($packet = $this->getPacket()) and
            $packet['status'] !== Job::STATUS_FAILED and
            ($e = json_decode($packet['exception'], true))
        ) {
            return $e['error'];
        }

        return 'Unknown exception';
    }
1152727
public function afterSaved($payload)
    {
        if (!request()->is('cms/revert/*') && !request()->is('cms/rollback/*/*')) {
            unset($payload->attributes['created_at']);
            unset($payload->attributes['updated_at']);
            unset($payload->original['created_at']);
            unset($payload->original['updated_at']);

            if ($payload->attributes != $payload->original) {
                Archive::create([
                    'token' => md5(time()),
                    'entity_id' => $payload->attributes['id'],
                    'entity_type' => get_class($payload),
                    'entity_data' => json_encode($payload->attributes),
                ]);
                Log::info(get_class($payload).' #'.$payload->attributes['id'].' was archived');
            }
        }
    }
516846
public function format($payload)
    {
        $payload = $this->fill($payload);
        return "[".$payload['responsecode']."] ".$payload['message']."<br />".$payload['verbosemessage']."<br/>".$payload['url'];

    }
438484
public function job_fail($handle, $job, $result) {

        $message = "($handle) Failed Job: $job: ".$result->getMessage();

        $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO);

        $this->log_result($handle, $result);
    }
240402
protected function decode($job)
    {
        $job->payload = json_decode($job->payload);

        $job->retried_by = collect(json_decode($job->retried_by))
                    ->sortByDesc('retried_at')->values();

        return $job;
    }
692637
private function isValidResult($payload): bool
    {
        if (!is_array($payload)) {
            return false;
        }

        $headerValid = array_key_exists('jsonrpc', $payload) && $payload['jsonrpc'] === '2.0';
        $resultValid = array_key_exists('result', $payload);
        $idValid     = array_key_exists('id', $payload);

        return $headerValid && $resultValid && $idValid;
    }
375616
private static function serializePayload($payload = '') : string
    {
        // If the payload is already JSON, return it
        if (\is_string($payload)) {
            return $payload;
        }

        $data = '';

        if (!empty($payload)) {
            $data = \json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
        }

        return $data;
    }