Skip to content

Commit 6000326

Browse files
Update Export status to Failed if the batch has been cancelled (#7)
1 parent 57d391f commit 6000326

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/Export/Jobs/CollateExportsAndUploadToDisk.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Spatie\MediaLibrary\MediaCollections\Exceptions\FileIsTooBig;
1616
use Spatie\SimpleExcel\SimpleExcelReader;
1717
use Spatie\SimpleExcel\SimpleExcelWriter;
18+
use Throwable;
1819

1920
class CollateExportsAndUploadToDisk implements ShouldQueue
2021
{
@@ -117,4 +118,11 @@ function getFilesSortedByIndex($uuid): array
117118

118119
return $filteredFiles;
119120
}
120-
}
121+
122+
public function failed(?Throwable $exception): void
123+
{
124+
$this->export->update([
125+
'status' => Status::FAILED->value
126+
]);
127+
}
128+
}

src/Export/Jobs/ExportProcessor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public function handle(): void
102102
"failedJobs" => $batch->failedJobs,
103103
]);
104104
})
105+
->finally(function (Batch $batch) use ($export) {
106+
if ($batch->cancelled()) {
107+
$export->update([
108+
'status' => Status::FAILED->value
109+
]);
110+
}
111+
})
105112
->allowFailures($this->allowFailures())
106113
->name($this->name())
107114
->onQueue(self::queueName())
@@ -193,4 +200,4 @@ protected function getQueryCount(): int
193200
{
194201
return $this->query()->count();
195202
}
196-
}
203+
}

src/Export/Jobs/ExportToCsv.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function __construct(
3333
*/
3434
public function handle(): void
3535
{
36+
if ($this->batch()->cancelled()) {
37+
return;
38+
}
39+
3640
$items = $this->processor->query()
3741
->lazy()
3842
->forPage($this->page, $this->perPage);
@@ -72,4 +76,4 @@ protected function storagePath($path = ''): string
7276

7377
return storage_path('app/temp/' . trim($path, '/'));
7478
}
75-
}
79+
}

0 commit comments

Comments
 (0)