Enable specifying a domain for nodelist import, and throwing exceptions when errors occur
This commit is contained in:
parent
c7187dbb0e
commit
531654724a
@ -16,6 +16,7 @@ class NodelistImport extends Command
|
|||||||
*/
|
*/
|
||||||
protected $signature = 'nodelist:import'
|
protected $signature = 'nodelist:import'
|
||||||
.' {file : File ID}'
|
.' {file : File ID}'
|
||||||
|
.' {domain? : Domain Name}'
|
||||||
.' {--D|delete : Delete old data for the date}'
|
.' {--D|delete : Delete old data for the date}'
|
||||||
.' {--U|unlink : Delete file after import}';
|
.' {--U|unlink : Delete file after import}';
|
||||||
|
|
||||||
@ -33,6 +34,6 @@ class NodelistImport extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
return Job::dispatchSync(File::findOrFail($this->argument('file')),$this->option('delete'),$this->option('unlink'));
|
return Job::dispatchSync(File::findOrFail($this->argument('file')),$this->argument('domain'),$this->option('delete'),$this->option('unlink'));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -24,6 +25,7 @@ class NodelistImport implements ShouldQueue
|
|||||||
private const importkey = 'nodelist';
|
private const importkey = 'nodelist';
|
||||||
|
|
||||||
private File $file;
|
private File $file;
|
||||||
|
private ?string $domain;
|
||||||
private bool $delete_file;
|
private bool $delete_file;
|
||||||
private bool $delete_recs;
|
private bool $delete_recs;
|
||||||
|
|
||||||
@ -31,12 +33,14 @@ class NodelistImport implements ShouldQueue
|
|||||||
* Import Nodelist constructor.
|
* Import Nodelist constructor.
|
||||||
*
|
*
|
||||||
* @param File $file
|
* @param File $file
|
||||||
|
* @param string|null $domain
|
||||||
* @param bool $delete_recs
|
* @param bool $delete_recs
|
||||||
* @param bool $delete_file
|
* @param bool $delete_file
|
||||||
*/
|
*/
|
||||||
public function __construct(File $file,bool $delete_recs=FALSE,bool $delete_file=TRUE)
|
public function __construct(File $file,string $domain=NULL,bool $delete_recs=FALSE,bool $delete_file=TRUE)
|
||||||
{
|
{
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
|
$this->domain = $domain;
|
||||||
$this->delete_file = $delete_file;
|
$this->delete_file = $delete_file;
|
||||||
$this->delete_recs = $delete_recs;
|
$this->delete_recs = $delete_recs;
|
||||||
}
|
}
|
||||||
@ -65,23 +69,23 @@ class NodelistImport implements ShouldQueue
|
|||||||
|
|
||||||
$matches = [];
|
$matches = [];
|
||||||
if ((! preg_match('/^;A\ /',$line)) || (! preg_match('/^;A\ (.*)\ Nodelist for ([MTWFS][a-z]+,\ [JFMASOND][a-z]+\ [0-9]{1,2},\ [0-9]{4})\ --\ Day\ number\ ([0-9]+)\ :\ ([0-9a-f]+)$/',$line,$matches))) {
|
if ((! preg_match('/^;A\ /',$line)) || (! preg_match('/^;A\ (.*)\ Nodelist for ([MTWFS][a-z]+,\ [JFMASOND][a-z]+\ [0-9]{1,2},\ [0-9]{4})\ --\ Day\ number\ ([0-9]+)\ :\ ([0-9a-f]+)$/',$line,$matches))) {
|
||||||
Log::error(sprintf('Nodelist file [%d] is not valid?',$this->file->id),['m'=>$matches,'l'=>$line]);
|
Log::error(sprintf('%s:Nodelist file [%d] is not valid?',self::LOGKEY,$this->file->id),['m'=>$matches,'l'=>$line]);
|
||||||
throw new \Exception('Invalid nodelist for file '.$this->file->id);
|
throw new \Exception('Invalid nodelist for file: '.$this->file->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_crc = $matches[4];
|
$file_crc = $matches[4];
|
||||||
$do = Domain::where('name',strtolower($matches[1]))->single();
|
$do = Domain::where('name',strtolower($matches[1] ?: $this->domain))->single();
|
||||||
|
|
||||||
if (! $do) {
|
if (! $do) {
|
||||||
Log::error(sprintf('%s:! Domain not found [%s].',static::LOGKEY,strtolower($matches[1])));
|
Log::error(sprintf('%s:! Domain not found [%s].',static::LOGKEY,strtolower($matches[1] ?: $this->domain)));
|
||||||
return;
|
throw new \Exception('Nodelist Domain not found: '.$this->file->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = Carbon::createFromFormat('D, M d, Y H:i',$matches[2].'0:00');
|
$date = Carbon::createFromFormat('D, M d, Y H:i',$matches[2].'0:00');
|
||||||
|
|
||||||
if ($date->dayOfYear != $matches[3]) {
|
if ($date->dayOfYear != $matches[3]) {
|
||||||
Log::error(sprintf('%s:! Nodelist date doesnt match [%d] (%d:%s).',static::LOGKEY,$matches[3],$date->dayOfYear,$date->format('Y-m-d')));
|
Log::error(sprintf('%s:! Nodelist date doesnt match [%d] (%d:%s).',static::LOGKEY,$matches[3],$date->dayOfYear,$date->format('Y-m-d')));
|
||||||
return;
|
throw new \Exception('Nodelist date doesnt match for file: '.$this->file->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('%s:Importing nodelist for [%s] dated [%s].',static::LOGKEY,$do->name,$date->format('Y-m-d')));
|
Log::debug(sprintf('%s:Importing nodelist for [%s] dated [%s].',static::LOGKEY,$do->name,$date->format('Y-m-d')));
|
||||||
|
Loading…
Reference in New Issue
Block a user