omniphx / forrest

A Laravel library for Salesforce
https://omniphx.github.io/forrest/
MIT License
257 stars 120 forks source link

Session store not set on request. but storage type:cache is already seted #305

Open andrecuellar opened 2 years ago

andrecuellar commented 2 years ago

Hello, I have a Job and command, my job is calling to a service class

Command:

    public function handle()
    {
        \App\Jobs\SyncFranchises::dispatch()->onQueue('sync');
    }

Job:

    public function handle()
    {
        $saveFranchise = new SaveFranchise();
        $saveFranchise->saveFranchise();
    }

service

    public function saveFranchise()
    {
        Forrest::authenticate();
        $productQuery = Forrest::query("SELECT Id,Name,Description,MarketArea__c, LastModifiedDate FROM
        Product2 WHERE Family = 'Lilly CloudRestaurant'");

        foreach ($productQuery['records'] as $product)
        {
            $franchise = new Franchise();
            $franchise->name = $product['Name'];
            $franchise->description = $product['Description'];
            $franchise->min_distance = round($product['MarketArea__c']);
            $franchise->salesforce_id = $product['Id'];
            $franchise->save();
        }
    }

I'm using Forrest::authenticate(); on the service, but I get this error on failed_jobs

RuntimeException: Session store not set on request. in /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Request.php:502
Stack trace:
#0 /var/www/html/vendor/omniphx/forrest/src/Omniphx/Forrest/Providers/Laravel/ForrestServiceProvider.php(38): Illuminate\Http\Request->session()
#1 /var/www/html/vendor/omniphx/forrest/src/Omniphx/Forrest/Providers/BaseServiceProvider.php(93): Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider->getStorage()

My config/forrest.php file has this

'authentication' => env('SF_AUTH_METHOD', 'OAuthJWT'),
'privateKey'     => file_get_contents(storage_path('Area_Check.key')),
'storage'        => [
    'type'          => 'cache', // Options include: 'session', 'cache', 'object'

I have read that with 'storage' => ['type' => 'cache'], it should be solved, but I still have the same problem when executing the command

omniphx commented 2 years ago

Your config/forrest.php should have a username configured as well but I'm not sure why you are getting an error about session store. Especially if you configured your app to use cache instead of session.

Which laravel version are you using?