Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Escavador/vespa-php
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.0
Choose a base ref
...
head repository: Escavador/vespa-php
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 18 commits
  • 18 files changed
  • 4 contributors

Commits on May 7, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    607b1ac View commit details
  2. Copy the full SHA
    e6463e0 View commit details

Commits on Jun 7, 2021

  1. Update the job failed warning

    Throw the exception to observers only when the job fails.
    icarojerry authored Jun 7, 2021
    Copy the full SHA
    969e23b View commit details

Commits on Jun 14, 2021

  1. Merge pull request #6 from Escavador/fix_job_failed_warning

    Update the job failed warning
    marivaldojr authored Jun 14, 2021
    Copy the full SHA
    93dee5d View commit details

Commits on Jul 14, 2021

  1. Copy the full SHA
    94aa579 View commit details
  2. Copy the full SHA
    f65898a View commit details
  3. Copy the full SHA
    9630171 View commit details
  4. Merge pull request #7 from Escavador/fix_exception_messages

    Add previous exception message when existing
    gabrielpeixoto authored Jul 14, 2021
    Copy the full SHA
    d6ed0ed View commit details

Commits on Aug 26, 2021

  1. reduces database calls

    gabrielpeixoto committed Aug 26, 2021
    Copy the full SHA
    e3bf15f View commit details

Commits on Jan 4, 2023

  1. Copy the full SHA
    281d48c View commit details

Commits on Jan 13, 2023

  1. Copy the full SHA
    461803c View commit details

Commits on Mar 3, 2023

  1. Merge pull request #8 from andrewalkermo/php-8.2

    Atualiza versão minima para php 8.2
    gabrielpeixoto authored Mar 3, 2023
    Copy the full SHA
    fdc9c37 View commit details

Commits on Apr 18, 2023

  1. suport Laravel 9

    gabrielpeixoto committed Apr 18, 2023
    Copy the full SHA
    2ce37fe View commit details

Commits on May 12, 2023

  1. Copy the full SHA
    5dd81a7 View commit details
  2. Copy the full SHA
    e7ceb33 View commit details
  3. Copy the full SHA
    b76dbd2 View commit details
  4. Copy the full SHA
    3a58c37 View commit details
  5. Copy the full SHA
    aadf482 View commit details
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -21,13 +21,13 @@
"issues": "https://github.com/escavador/vespa-php/issues"
},
"require": {
"php": "^7.1",
"php": "^8.2",
"ext-json": ">=1.3.7",
"guzzlehttp/ringphp": "~1.0",
"guzzlehttp/guzzle": "7.0.*"
"guzzlehttp/guzzle": ">=6.4.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
17 changes: 10 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.3-fpm AS composer
FROM php:8.2-fpm AS composer

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@@ -11,14 +11,17 @@ RUN apt update \
&& rm /etc/apt/preferences.d/no-debian-php \
&& apt update -yqq \
&& apt install -y --force-yes --no-install-recommends \
build-essential \
curl \
git \
locales
build-essential \
curl \
git \
locales \
libzip-dev \
zip \
&& docker-php-ext-install zip

RUN composer install
RUN composer update

FROM php:7.3-fpm
FROM php:8.2-fpm

WORKDIR /var/www

6 changes: 5 additions & 1 deletion src/Commands/FeedCommand.php
Original file line number Diff line number Diff line change
@@ -288,9 +288,12 @@ private function processNow($model_definition, $model_class, $model)

private function processAsync($model_definition, $model_class, $model, $queue = null)
{
$all_document_ids = $model_class::getVespaDocumentIdsToIndex($this->limit);

$items = $this->limit;
$total_scheduled = 0;
$total_documents = 0;

while ($items > 0) {
if ($items >= $this->bulk) {
$items -= $this->bulk;
@@ -300,7 +303,8 @@ private function processAsync($model_definition, $model_class, $model, $queue =
$items = 0;
}

$document_ids = $model_class::getVespaDocumentIdsToIndex($requested_documents);
$document_ids = array_splice($all_document_ids, 0, $requested_documents);

$count_docs = count($document_ids);

if ($document_ids !== null && $count_docs <= 0) {
6 changes: 3 additions & 3 deletions src/Common/VespaExceptionSubject.php
Original file line number Diff line number Diff line change
@@ -18,15 +18,15 @@ final public static function notifyObservers(VespaException $expection)
}
}

private function __construct()
public function __construct()
{
}

private function __clone()
public function __clone()
{
}

private function __wakeup()
public function __wakeup()
{
}
}
4 changes: 3 additions & 1 deletion src/Exception/VespaException.php
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ class VespaException extends \Exception
{
public function __construct($message, \Exception $exception = null)
{
parent::__construct($message, 001, $exception);
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

parent::__construct("{$message}{$previous_message}", 001, $exception);
}
}
6 changes: 4 additions & 2 deletions src/Exception/VespaExecuteJobException.php
Original file line number Diff line number Diff line change
@@ -9,10 +9,12 @@ class VespaExecuteJobException extends VespaException

public function __construct(string $job_class, string $document_type, \Exception $exception = null, string $message = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if (!$message) {
parent::__construct("[{$document_type}] The job $job_class process failed", $exception);
parent::__construct("[{$document_type}] The job $job_class process failed.$previous_message", $exception);
} else {
parent::__construct("[{$document_type}] $job_class - $message", $exception);
parent::__construct("[{$document_type}] $job_class - $message$previous_message", $exception);
}

$this->code = 600;
4 changes: 3 additions & 1 deletion src/Exception/VespaFailDeleteDocumentException.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@ class VespaFailDeleteDocumentException extends VespaException

public function __construct($definition, string $scheme, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: An error occurred while deleting the document to the scheme : $scheme.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: An error occurred while deleting the document to the scheme : $scheme.$previous_message", $exception);

$this->code = 100;
$this->definition = $definition;
4 changes: 3 additions & 1 deletion src/Exception/VespaFailGetDocumentException.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ class VespaFailGetDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, string $scheme, \Exception $exception)
{
parent::__construct("[{$definition->getDocumentType()}]: An error occurred while getting the document to the scheme: $scheme", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: An error occurred while getting the document to the scheme: $scheme.$previous_message", $exception);

$this->code = $exception->getCode();
$this->definition = $definition;
4 changes: 3 additions & 1 deletion src/Exception/VespaFailSearchException.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,9 @@ class VespaFailSearchException extends VespaException

public function __construct(array $data, \Exception $exception = null)
{
parent::__construct("An error occurred while performing the search on Vespa. Payload: " . json_encode($data), $exception);
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

parent::__construct("An error occurred while performing the search on Vespa. Payload: " . json_encode($data) . $previous_message, $exception);

$this->code = 300;
$this->payload = $data;
4 changes: 3 additions & 1 deletion src/Exception/VespaFailSendDocumentException.php
Original file line number Diff line number Diff line change
@@ -12,7 +12,9 @@ class VespaFailSendDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, AbstractDocument $document, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not indexed to Vespa.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not indexed to Vespa.{$previous_message}", $exception);

$this->code = 400;
$this->document = $document;
4 changes: 3 additions & 1 deletion src/Exception/VespaFailUpdateDocumentException.php
Original file line number Diff line number Diff line change
@@ -12,7 +12,9 @@ class VespaFailUpdateDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, AbstractDocument $document, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not updated to Vespa.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not updated to Vespa.$previous_message", $exception);

$this->code = 500;
$this->document = $document;
6 changes: 4 additions & 2 deletions src/Exception/VespaFeedException.php
Original file line number Diff line number Diff line change
@@ -8,10 +8,12 @@ class VespaFeedException extends VespaException

public function __construct(string $model, \Exception $exception = null, string $message = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if (!$message) {
parent::__construct("[{$model}] Feed process failed", $exception);
parent::__construct("[{$model}] Feed process failed.$previous_message", $exception);
} else {
parent::__construct("[{$model}] $message", $exception);
parent::__construct("[{$model}] $message$previous_message", $exception);
}

$this->code = 600;
4 changes: 3 additions & 1 deletion src/Exception/VespaInvalidHostException.php
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ class VespaInvalidHostException extends VespaException
{
public function __construct(\Exception $exception = null)
{
parent::__construct("Invalid Vespa Host", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("Invalid Vespa Host.$previous_message", $exception);

$this->code = 700;
}
4 changes: 3 additions & 1 deletion src/Exception/VespaInvalidYQLQueryException.php
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@ class VespaInvalidYQLQueryException extends VespaException
{
public function __construct($message = null, \Exception $exception = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if ($message != null) {
$message = " $message";
}
parent::__construct("Could not instantiate query from YQL.$message", $exception);
parent::__construct("Could not instantiate query from YQL.$message${previous_message}", $exception);

$this->code = 800;
}
25 changes: 19 additions & 6 deletions src/Jobs/FeedDocumentJob.php
Original file line number Diff line number Diff line change
@@ -6,12 +6,14 @@
use Escavador\Vespa\Common\LogManager;
use Escavador\Vespa\Common\Utils;
use Escavador\Vespa\Common\VespaExceptionSubject;
use Escavador\Vespa\Enum\LogManagerOptionsEnum;
use Escavador\Vespa\Exception\VespaFeedException;
use Escavador\Vespa\Models\DocumentDefinition;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Queue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
@@ -59,7 +61,7 @@ public function handle()

try {
if (count($documents) == 0) {
$this->logger->log("[$this->model]: No documents to be indexed were returned", "info");
$this->logger->log("[$this->model]: No documents to be indexed were returned", LogManagerOptionsEnum::INFO);
throw new VespaFeedException($this->model, null, "It was not possible to index any document to the Vespa.");
}

@@ -96,12 +98,23 @@ public function handle()
$this->model_class::markAsVespaNotIndexed($chunk);
}
}
$e = new VespaFeedException($this->model, $ex);
VespaExceptionSubject::notifyObservers($e);
throw $e;

$this->fail($ex);
return;
}
$total_duration = Carbon::now()->diffInSeconds($start_time);
$this->logger->log("[$this->model]: Vespa was fed in " . gmdate('H:i:s:m', $total_duration), "info");
$this->logger->log("[$this->model]: $count_indexed of " . count($documents) . " were indexed in Vespa.", "debug");
$this->logger->log("[$this->model]: Vespa was fed in " . gmdate('H:i:s:m', $total_duration), LogManagerOptionsEnum::INFO);
$this->logger->log("[$this->model]: $count_indexed of " . count($documents) . " were indexed in Vespa.", LogManagerOptionsEnum::DEBUG);
}

/**
* The job failed to process.
*
* @param \Exception $exception
* @return void
*/
public function failed(\Exception $exception = null)
{
VespaExceptionSubject::notifyObservers(new VespaFeedException($this->model, $exception));
}
}
3 changes: 2 additions & 1 deletion src/Jobs/UpdateDocumentJob.php
Original file line number Diff line number Diff line change
@@ -96,7 +96,8 @@ public function handle()

$e = new VespaFeedException($this->document_type, $ex);
VespaExceptionSubject::notifyObservers($e);
throw $e;
$this->fail($e);
return;
}
$total_duration = Carbon::now()->diffInSeconds($start_time);
$this->logger->log("[$this->document_type]: " . class_basename(self::class) . " was fed in " . gmdate('H:i:s:m', $total_duration), "info");
4 changes: 1 addition & 3 deletions src/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
@@ -34,14 +34,12 @@ protected function getStub($table, $create)
/**
* Populate the place-holders in the migration stub.
*
* @param string $name
* @param string $stub
* @param string $table
* @return string
*/
protected function populateStub($name, $stub, $table)
protected function populateStub($stub, $table)
{
$stub = str_replace('DummyClass', $this->getClassName($name), $stub);
$stub = str_replace('DummyTable', $table, $stub);
$stub = str_replace('DummyColumnNameStatus', config('vespa.model_columns.status', ''), $stub);
$stub = str_replace('DummyColumnNameDate', config('vespa.model_columns.date', ''), $stub);
2 changes: 1 addition & 1 deletion src/Migrations/stubs/blank.stub
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class DummyClass extends Migration
return new class extends Migration
{
protected $table = 'DummyTable';
protected $vespa_last_indexed_date = 'DummyColumnNameDate';