Skip to content

Commit a31f3ac

Browse files
authored
Merge pull request #186 from astuteo/fix-empty-tempfile
fix: re-download bulk file if an empty temp file exists
2 parents e67a711 + 7ce872a commit a31f3ac

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/jobs/ProcessBulkOperationData.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ protected function loadData(): Batchable
6767
$this->tempFilePath = Assets::tempFilePath('jsonl');
6868
}
6969

70+
$fileExists = file_exists($this->tempFilePath);
71+
$fileSize = $fileExists ? filesize($this->tempFilePath) : 0;
72+
73+
// If somehow a zero-byte file exists, remove it to force a re-download
74+
if ($fileExists && $fileSize === 0) {
75+
FileHelper::unlink($this->tempFilePath);
76+
$fileExists = false;
77+
}
78+
7079
// Only re-download if the file doesn't already exist
7180
// If the queue is using multiple workers and the file leaks between them,
72-
if (!file_exists($this->tempFilePath)) {
81+
if (!$fileExists) {
7382
// Retrieve remote file contents
7483
$client = Craft::createGuzzleClient();
7584
$response = $client->get($this->dataUrl);

0 commit comments

Comments
 (0)