#Serialization error thrown when calling `Cache` from batch `finally`

2 messages · Page 1 of 1 (latest)

rotund trout
#

Hoping someone can shed some light on this. I'm looking to remove some keys from the cache (file driver) after all my batched jobs have finished and for some reason I'm getting Serialization of 'CurlHandle' is not allowed

I've tried abstracting this to a method in the same class, and swapping to Artisan::call('cache:forget', ['key' => '...']); and the same error is thrown. Dispatching a dedicated job to clear the cache is the only solution that worked.

Should I not be able to call cache/artisan methods from within here? Doesn't seem right that I have to dispatch a job to just clear the cache, but I'll stick to it if I have to. I can confirm that my jobs do include the Batchable trait.

$batch = Bus::batch([])
    ->name("BC Order Transfer - {$this->sourceStoreHash} -> {$this->destinationStoreHash}")
    ->onQueue('bc.orders')
    ->allowFailures()
    ->finally(function (Batch $batch) {
        if ($batch->hasFailures()) {
            //
        }

        Cache::forget("products|{$this->sourceStoreHash}");
        Cache::forget("variants|{$this->sourceStoreHash}");
        Cache::forget("products|{$this->destinationStoreHash}");
        Cache::forget("variants|{$this->destinationStoreHash}");
    })
    ->dispatch();
thin brook