Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow checks to be serializable #230

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

Riley19280
Copy link
Contributor

@Riley19280 Riley19280 commented Jun 26, 2024

Currently, trying to use a conditional such as ->if or ->unless on a QueueCheck does not work, and throws an error when calling DispatchQueueCheckJobsCommand. The error message is Serialization of 'Closure' is not allowed, because it can't serialize the run checks. For example, the following check would throw this error because of the closure.

QueueCheck::new()->if(fn() => true),

This PR allows all checks to be serializable and correctly pushed to queues

@freekmurze freekmurze merged commit 1ea1950 into spatie:main Jun 27, 2024
11 checks passed
@freekmurze
Copy link
Member

Thank you!

@sebastiaanluca
Copy link

We just deployed this to production and got some exceptions:

  Laravel\SerializableClosure\SerializableClosure::__construct(): Argument #1 ($closure) must be of type Closure, true given, called in /vendor/spatie/laravel-health/src/Checks/Check.php on line 133

For

Schedule::command(DispatchQueueCheckJobsCommand::class)
    ->everyMinute()
    ->environments(['staging', 'production']);

$shouldRun is true which it can't serialize.

Line:

$serializableClosures[] = new SerializableClosure($shouldRun);

Data:

array:8 [
  "expression" => "* * * * *"
  "name" => null
  "label" => null
  "shouldRun" => array:1 [
    0 => true
  ]
  "cacheKey" => "health:checks:queue:latestHeartbeatAt"
  "cacheStoreName" => null
  "failWhenTestJobTakesLongerThanMinutes" => 10
  "onQueues" => array:2 [
    0 => "high"
    1 => "default"
  ]
]

@Riley19280
Copy link
Contributor Author

Fixed in #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants