Add data export retry and cancel controls
This commit is contained in:
@@ -19,6 +19,8 @@ class DataExport extends Model
|
||||
|
||||
public const STATUS_FAILED = 'failed';
|
||||
|
||||
public const STATUS_CANCELED = 'canceled';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'tenant_id',
|
||||
@@ -58,6 +60,38 @@ class DataExport extends Model
|
||||
return $this->status === self::STATUS_READY;
|
||||
}
|
||||
|
||||
public function canRetry(): bool
|
||||
{
|
||||
return in_array($this->status, [self::STATUS_FAILED, self::STATUS_CANCELED], true);
|
||||
}
|
||||
|
||||
public function canCancel(): bool
|
||||
{
|
||||
return in_array($this->status, [self::STATUS_PENDING, self::STATUS_PROCESSING], true);
|
||||
}
|
||||
|
||||
public function resetForRetry(): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => self::STATUS_PENDING,
|
||||
'error_message' => null,
|
||||
'path' => null,
|
||||
'size_bytes' => null,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function markCanceled(?string $reason = null): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => self::STATUS_CANCELED,
|
||||
'error_message' => $reason ?: 'Canceled by superadmin.',
|
||||
'path' => null,
|
||||
'size_bytes' => null,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function hasExpired(): bool
|
||||
{
|
||||
return $this->expires_at !== null && $this->expires_at->isPast();
|
||||
|
||||
Reference in New Issue
Block a user