wip
This commit is contained in:
parent
e1a248f678
commit
026e2601c4
|
|
@ -48,7 +48,7 @@ public function handle(): void
|
|||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
logger('error', $process->getErrorOutput());
|
||||
logger('error', [$process->getErrorOutput()]);
|
||||
}
|
||||
logger($process->getOutput());
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Process\Exceptions\ProcessFailedException;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
|
@ -76,6 +77,7 @@ public static function handleFor(Project $project, $year, $startWeekNumber)
|
|||
{
|
||||
logger("ProjectMosiacGeneratorJob::handleFor(week $startWeekNumber, year $year)");
|
||||
if ($project->hasInvalidMosaicFor($year, $startWeekNumber)) {
|
||||
logger("ProjecMosaicGeneratorJob::handleFor(week $startWeekNumber, year $year): InvalidMosaic.");
|
||||
return new NullJob();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public function saveMosaic()
|
|||
], [
|
||||
'path' => $this->project->getMosaicPath(),
|
||||
]);
|
||||
|
||||
logger(sprintf('in SaveMosaic: %s, week: %d, year: %d', $mosaic->name, $mosaic->week, $mosaic->year));
|
||||
ProjectMosiacGeneratorJob::dispatch($mosaic);
|
||||
|
||||
$this->showCreateModal = false;
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public function allMosaicsPresent(Carbon $endDate): bool
|
|||
{
|
||||
// end date is in the future
|
||||
if ($endDate->isFuture()) {
|
||||
throw new \Exception('End date is in the future');
|
||||
throw new \Exception('Mosaic can be generated for the future. Change the end date.');
|
||||
}
|
||||
|
||||
$mosaicsNotPresentInFilesystem = $this->getMosaicFilenameListByEndDate($endDate)
|
||||
|
|
@ -155,7 +155,7 @@ public function allMosaicsPresent(Carbon $endDate): bool
|
|||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
public function getMosaicFilenameListByEndDate(Carbon $endDate): Collection
|
||||
public static function getMosaicFilenameListByEndDate(Carbon $endDate): Collection
|
||||
{
|
||||
$result = collect([]);
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
|
|
@ -304,7 +304,7 @@ public function scheduleReport($year = null, $week = null)
|
|||
Bus::chain([
|
||||
Bus::batch($this->getFileDownloadsFor($year, $week)),
|
||||
Bus::batch($this->getMosaicsFor($year, $week)),
|
||||
Bus::batch($this->getReportFor($year, $week, true)),
|
||||
Bus::batch([$this->getReportFor($year, $week, true)]),
|
||||
])
|
||||
->dispatch();
|
||||
return "done";
|
||||
|
|
@ -319,30 +319,28 @@ public function getReportFor($year, $week, $sendMail = false)
|
|||
'path' => 'reports/week_'.$week.'_'.$year.'.docx',
|
||||
]);
|
||||
|
||||
return [new ProjectReportGeneratorJob($report, $sendMail)];
|
||||
return (new ProjectReportGeneratorJob($report, $sendMail));
|
||||
}
|
||||
|
||||
public function getFileDownloadsFor($year, $startWeekNumber)
|
||||
public function getFileDownloadsFor($year, $startWeekNumber):array
|
||||
{
|
||||
$endOfRange = now()->setISODate($year, $startWeekNumber)->endOfWeek();
|
||||
$startOfRange = (clone $endOfRange)->subWeeks(3)->startOfWeek();
|
||||
|
||||
$dateRange = CarbonPeriod::create($startOfRange, $endOfRange);
|
||||
|
||||
$return = collect($dateRange)
|
||||
return collect($dateRange)
|
||||
->map(fn($date) => ProjectDownloadTiffJob::handleForDate($this, $date))
|
||||
->filter()
|
||||
->toArray();
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function getMosaicsFor($year, $startWeekNumber)
|
||||
{
|
||||
$return = collect(range(0, 3))
|
||||
logger(sprintf('in Get Mosaics for year %s week %d', $year, $startWeekNumber));
|
||||
return collect(range(0, 3))
|
||||
->map(fn($weekDiff) => ProjectMosiacGeneratorJob::handleFor($this, $year, $startWeekNumber - $weekDiff))
|
||||
->filter()
|
||||
->toArray();
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
<x-slot name="form">
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-label for="year" value="{{ __('Year') }}"/>
|
||||
<x-input id="year" type="text" class="mt-1 block w-full" wire:model.live="formData.year" autofocus/>
|
||||
<x-input id="year" type="number" min="1900" max="{{\Carbon\Carbon::now()->year}}" class="mt-1 block w-full" wire:model.live="formData.year" autofocus/>
|
||||
<x-input-error for="formData.year" class="mt-2"/>
|
||||
</div><div class="col-span-6 sm:col-span-4">
|
||||
<x-label for="week" value="{{ __('Week') }}"/>
|
||||
<x-input id="week" type="text" class="mt-1 block w-full" wire:model.live="formData.week" autofocus/>
|
||||
<x-input id="week" type="number" min="1" max="53" class="mt-1 block w-full" wire:model.live="formData.week" autofocus/>
|
||||
<x-input-error for="formData.week" class="mt-2"/>
|
||||
<x-input-error for="formData" class="mt-2"/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class="flex flex-col md:flex-row">
|
|||
<div id="mail"
|
||||
class="flex flex-col md:w-2/3"
|
||||
x-data="{showMail: null}"
|
||||
x-init="showMail = !($wire.formData['mail_subject'] === null || $wire.formData['mail_subject'] === undefined || $wire.formData['mail_subject'] === '')"
|
||||
x-init="showMail = $wire.formData['mail_scheduled']"
|
||||
> {{-- flex col--}}
|
||||
<div class="flex justify-between my-4">
|
||||
<div class="inline-flex items-center gap-2">
|
||||
|
|
@ -79,8 +79,7 @@ class="flex flex-col md:w-2/3"
|
|||
</div>
|
||||
</div>
|
||||
<label class="inline-flex items-center cursor-pointer gap-4">
|
||||
<input x-ref="subject" type="checkbox" class="sr-only peer" wire:model="formData.mail_scheduled" @click="showMail = $el.checked" x-init="$el.checked = showMail">
|
||||
{{-- TODO doesn't save mail_scheduled in DB--}}
|
||||
<input type="checkbox" class="sr-only peer" wire:model.live="formData.mail_scheduled" @click="showMail = $el.checked">
|
||||
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-300 dark:peer-focus:ring-indigo-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-indigo-600"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -90,14 +90,15 @@ public function when_not_all_mosaics_are_present_it_should_return_an_exception()
|
|||
/** @test */
|
||||
public function when_all_mosaics_are_present_it_should_return_true()
|
||||
{
|
||||
// TODO CHeck with Martin the Leading Zero test
|
||||
$project = Mockery::mock(Project::class)->makePartial();
|
||||
$lastDate = Carbon::parse('2021-01-01');
|
||||
$lastDate = Carbon::parse('2021-01-22');
|
||||
$project->shouldReceive('getMosaicList')->andReturn(
|
||||
collect([
|
||||
"chemba/weekly_mosaic/week_53_2020.tif",
|
||||
"chemba/weekly_mosaic/week_52_2020.tif",
|
||||
"chemba/weekly_mosaic/week_51_2020.tif",
|
||||
"chemba/weekly_mosaic/week_50_2020.tif",
|
||||
"chemba/weekly_mosaic/week_03_2021.tif",
|
||||
"chemba/weekly_mosaic/week_02_2021.tif",
|
||||
"chemba/weekly_mosaic/week_01_2021.tif",
|
||||
]));
|
||||
|
||||
$this->assertTrue($project->allMosaicsPresent($lastDate));
|
||||
|
|
@ -126,7 +127,7 @@ public function when_not_mosaics_are_present_it_should_throw_an_exception_listin
|
|||
public function when_all_mosaics_are_present_is_called_with_future_date_it_should_throw_an_expection()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('End date is in the future');
|
||||
$this->expectExceptionMessage('Mosaic can be generated for the future. Change the end date.');
|
||||
$this->seed();
|
||||
$project = Project::find(1);
|
||||
Carbon::setTestNow(Carbon::parse('2020-01-01'));
|
||||
|
|
@ -139,9 +140,10 @@ public function when_all_mosaics_are_present_is_called_with_future_date_it_shoul
|
|||
public function getMosiacFileListByEndDate_should_return_four_filenames()
|
||||
{
|
||||
$this->seed();
|
||||
/* @var Project $project */
|
||||
$project = Project::find(1);
|
||||
$lastDate = Carbon::parse('2021-01-01');
|
||||
$list = $project->getMosiacFilenameListByEndDate($lastDate);
|
||||
$list = $project::getMosaicFilenameListByEndDate($lastDate);
|
||||
$this->assertCount(4, $list);
|
||||
$this->assertEquals([
|
||||
"week_53_2020.tif",
|
||||
|
|
@ -154,32 +156,35 @@ public function getMosiacFileListByEndDate_should_return_four_filenames()
|
|||
/** @test */
|
||||
public function when_getFileDownloadsFor_is_called_it_returns_a_collection_of_seven_downloads_jobs()
|
||||
{
|
||||
/* @var Project $project */
|
||||
$project = Project::create([
|
||||
'name' => 'project_name',
|
||||
'download_path' => 'project_download_path',
|
||||
]);
|
||||
|
||||
$downloads = $project->getFileDownloadsFor(2023, 2);
|
||||
$this->assertCount(3 * 7, $downloads);
|
||||
$downloads->each(fn($job) => $this->assertInstanceOf(ProjectDownloadTiffJob::class, $job));
|
||||
$downloads = $project->getFileDownloadsFor(2023, 22);
|
||||
$this->assertCount(4 * 7, $downloads);
|
||||
collect($downloads)->each(fn($job) => $this->assertInstanceOf(ProjectDownloadTiffJob::class, $job));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function when_getMosaicsFor_is_called_it_returns_a_collection_of_seven_downloads_jobs()
|
||||
{
|
||||
/* @var Project $project */
|
||||
$project = Project::create([
|
||||
'name' => 'project_name',
|
||||
'download_path' => 'project_download_path',
|
||||
]);
|
||||
|
||||
$mosaics = $project->getMosaicsFor(2023, 2);
|
||||
$this->assertCount(3, $mosaics);
|
||||
$mosaics->each(fn($job) => $this->assertInstanceOf(ProjectMosiacGeneratorJob::class, $job));
|
||||
$this->assertCount(4, $mosaics);
|
||||
collect($mosaics)->each(fn($job) => $this->assertInstanceOf(ProjectMosiacGeneratorJob::class, $job));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function when_getReport_is_called_it_returns_a_jobs()
|
||||
{
|
||||
/* @var Project $project*/
|
||||
$project = Project::create([
|
||||
'name' => 'project_name',
|
||||
'download_path' => 'project_download_path',
|
||||
|
|
@ -230,7 +235,7 @@ public function when_friday_and_first_week_it_should_schedule($date, $day, $resu
|
|||
$this->assertEquals($result, $project->shouldSchedule());
|
||||
}
|
||||
|
||||
public function scheduleDayProvider(){
|
||||
public static function scheduleDayProvider(){
|
||||
return [
|
||||
['date' => '2024-03-01', 'day' => 'Friday', 'result' => true],
|
||||
['date' => '2024-03-02', 'day' => 'Saturday', 'result' => false],
|
||||
|
|
|
|||
Loading…
Reference in a new issue