-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into alain_translations
# Conflicts: # composer.lock # resources/views/dashboard.blade.php
- Loading branch information
Showing
11 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\StatementIndexRange; | ||
use App\Jobs\StatementPreprodSyncChunk; | ||
use App\Jobs\StatementSearchableChunk; | ||
use App\Services\DayArchiveService; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class StatementsPreprodSyncDateSeq extends Command | ||
{ | ||
use CommandTrait; | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'statements:preprod-sync-date-seq {date=yesterday} {chunk=500}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Sync statements for a day to the preprod DB'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(DayArchiveService $day_archive_service): void | ||
{ | ||
$chunk = $this->intifyArgument('chunk'); | ||
$date = $this->sanitizeDateArgument(); | ||
|
||
$min = $day_archive_service->getFirstIdOfDate($date); | ||
$max = $day_archive_service->getLastIdOfDate($date); | ||
|
||
if ($min && $max) { | ||
Log::info('Syncing started for date: ' . $date->format('Y-m-d') . ' at ' . Carbon::now()->format('Y-m-d H:i:s')); | ||
StatementPreprodSyncChunk::dispatch($min, $max, $chunk); | ||
} else { | ||
Log::warning('Not able to obtain the highest or lowest ID for the day: ' . $date->format('Y-m-d')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Statement; | ||
use App\Services\StatementSearchService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Log; | ||
use JsonException; | ||
|
||
class StatementPreprodSyncChunk implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public int $min, public int $max, public int $chunk) | ||
{ | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* @throws JsonException | ||
*/ | ||
public function handle(StatementSearchService $statement_search_service): void | ||
{ | ||
// Set this in cache, to emergency stop reindexing. | ||
$stop = Cache::get('stop_reindexing', false); | ||
if (!$stop) { | ||
$end = $this->min + $this->chunk; | ||
|
||
if ($end > $this->max) { | ||
$end = $this->max; | ||
} | ||
|
||
|
||
// Dispatch the next one | ||
if ($end < $this->max) { | ||
$next_min = $this->min + $this->chunk + 1; | ||
// Start the next one. | ||
self::dispatch($next_min, $this->max, $this->chunk); | ||
} | ||
|
||
$range = range($this->min, $end); | ||
// Bulk sync | ||
|
||
$to_insert = DB::connection('mysql::read')->table('statements')->whereIn('id', $range)->get()->map(function ($item){ | ||
return get_object_vars($item); | ||
})->toArray(); | ||
Statement::on('mysqlpreprod')->insert($to_insert); | ||
|
||
if ($end >= $this->max) { | ||
Log::info('StatementPreprodSyncChunk Max Reached at ' . Carbon::now()->format('Y-m-d H:i:s')); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.