ksassnowski/venture

Venture incompatible with Laravel Jobs side by side usage.

Closed this issue · 7 comments

I attempted to add the package and use it on one process, but I am now unable to run any of my other non-venture jobs.

So I started commenting out the events in the venture provider, then ran my test for my regular jobs, which are Laravel Actions Job, and it passed. All stim from the JobProcessed event appears to be attempting to unserialize a base64, which fails because regular jobs do not have base64 as far as I know?

Step 1:

$this->app['events']->subscribe(WorkflowEventSubscriber::class);

Step 2:

private function withWorkflowJob(

Step 3:

return $this->serializer->unserialize(

Step 4:

public function unserialize(string $serializedJob): ?WorkflowableJob

So seems to be incompatible with Laravel Jobs and it's venture all or nothing.

Hi @dragonfire1119,

Can you elaborate on Venture "failing"? Do you receive an exception when attempting to process regular jobs?

FYI I'm running Venture in production and am not having any issues with normal jobs (queued or otherwise). Can you provide what queue driver you're using and a code example?

All stim from the JobProcessed event appears to be attempting to unserialize a base64

Base 64 encoded jobs are and decoded automatically, but this is detected before actually performing the decoding on the job. Otherwise, a standard PHP unserialize() is taken place:

public function unserialize(string $serializedJob): ?WorkflowableJob
{
if ($this->isPostgresConnection() && !Str::contains($serializedJob, [':', ';'])) {
$serializedJob = \base64_decode($serializedJob, true);
if (false === $serializedJob) {
throw new UnserializeException('Unable to base64 decode job');
}
}
$result = @\unserialize($serializedJob);
if (!\is_object($result)) {
throw new UnserializeException('Unable to unserialize job');
}

Then, once unserialized, detection is done on whether the job is actually a Venture Workflow Job before continuing:

try {
return WorkflowStepAdapter::fromJob($result);
} catch (InvalidArgumentException) {
return null;
}
}

@stevebauman thanks for the reply.

I'm using Laravel Actions jobs to dispatch out a job that simply deletes a user account.

class DeleteUser
{
    use AsAction;

    public function handle(User $user)
    {
        // Delete user
        $user->forceDelete();
    }

    public function asJob($user): void
    {
        $this->handle($user);
    }
}

Error:

No query results for model [App\Models\User].

at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:594
    590▕         if (!is_null($model = $this->first($columns))) {
    591▕             return $model;
    592▕         }
    593▕
  ➜ 594▕         throw (new ModelNotFoundException)->setModel(get_class($this->model));
    595▕     }
    596▕
    597▕     /**
    598▕      * Execute the query and get the first result or call a callback.

When I remove venture from composer it passes my test with no errors.

Also when I comment out the

$this->app['events']->subscribe(WorkflowEventSubscriber::class); 

it passes my test. Using sync driver for testing.

Thanks for those details @dragonfire1119.

Are you able to share your test case using the Laravel Actions package so I can try to replicate?

@stevebauman

  1. Create the user in a Laravel factory
  2. Act as the user
  3. Run DeleteUserProfile::dispatch($profile); with sync as connection.
<?php

it('should delete profile with team members', function () {

$user = User::factory()->create();

$this->actingAs($user, 'api');

DeleteUser::dispatch($user);

})->group('user');

.env

QUEUE_CONNECTION=sync

Just tried it without Laravel Actions and a normal Job still the same error.

I added a ray right before the $user->delete() and it's showing the user in ray so it's weird.

Adding a return null; before this makes my test pass:

$result = @\unserialize($serializedJob);

Started up a horizon queue and it seems to complete the job so this error is just on the sync driver.

I'm unable to reproduce this on a fresh installation of Laravel. The job gets dispatched just fine for me. I'm also using Venture in an app that uses regular Laravel jobs alongside workflow jobs without issues.

Can you check if the same error happens when you use a job that doesn't include an Eloquent model? Because your error seems to be about Eloquent not being able to find the user.

Can you please provide a repository with a minimal reproduceable example?

Closing this due to inactivity. Feel free to reopen if you have more information.