0

Im struggling to configure the queue connection in lumen 8 project, im my database.php i have 2 connections lets say A and B, A to connect to DB_A and B for DB_B.

my database.php looks like this :

// database.php
'connections' => [
    'connection_A' => array(
        'driver' => env('DB_A',''),
        'host' => env('DB_A_HOST',''),
        'port' => env('DB_A_PORT',''),
        'database' => env('DB_A_DATABASE',''),
        'username' => env('DB_A_USERNAME',''),
        'password' => env('DB_A_PASSWORD',''),
        'charset'  => 'utf8',
        'prefix' => '',
        'schema' => 'public',
    ),

    'connection_B' => array(
        'driver' => env('DB_B',''),
        'host' => env('DB_B_HOST',''),
        'port' => env('DB_B_PORT',''),
        'database' => env('DB_B_DATABASE',''),
        'username' => env('DB_B_USERNAME',''),
        'password' => env('DB_B_PASSWORD',''),
        'charset'  => 'utf8',
        'prefix' => '',
        'schema' => env('DB_B_SCHEMA'),
    ),

i use the connection A to fetch some data from DB_A and run a job using database driver on DB_B so my tables jobs,failed_jobs are both in DB_B

i configured my queue.php like this

// queue.php
'connections' => [
   
    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
        'connection' => 'connection_B', // not working => table jobs not found
        'database' => 'connection_B', //  not working => table jobs not found
    ],

],

'failed' => [
    'driver' => 'database',
    'database' => 'connection_B', // works for some reason
    'table' => 'failed_jobs',
],

so my question is how to tell the the queue what database connection to use ?

i tried to force the connection before dispatching the job like this :

Config::set('database.connections.connection_B.database', env('DB_B_DATABASE'));
Config::set('database.connections.connection_B.schema', env('DB_B_SCHEMA'));
DB::purge('connection_B');
DB::reconnect('connection_B');

and i also tried to set the queue connection like this :

$connection = Queue::connection('connection_B');
$connection->pushOn('my_queue', $job);

i get an exception

No connector for []. {"exception":"[object] (InvalidArgumentException(code: 0): No connector for [].

am i missing or misunderstanding something ?

ps : in my app.php i load the queue.php and database.php.

$app->configure('app');
$app->configure('database');
$app->configure('queue');

and i dispatch my job like this :

$jobId = Queue::push((new CreatePdfJob($datas)),null,'my-queue');

Thank you for your help.

Mr.Sef
  • 49
  • 1
  • 4
  • Did you migrate fot table creation? – Maksim Aug 13 '21 at 20:56
  • yes , i used the command php artisan queue:table to create the migration and php artisan migrate --database=connection_B to run it on the data base B – Mr.Sef Aug 13 '21 at 21:02
  • Do you see it in database? If not - try to set connection in migration file by override connection propertt – Maksim Aug 13 '21 at 21:16
  • yes , i can see the jobs table and failed_jobs, the tables are where they should be, also both connection works fine ican get / save data . my question is somehting like in the arrays 'database' what key to put to tell the queue what connection to use ? is it 'connection' like redis config or 'database' like the failed, or something else ? – Mr.Sef Aug 13 '21 at 21:27
  • Oh, you must use `database` connection name, array key in `queue.connections`. Or rename in to `database_B` – Maksim Aug 13 '21 at 21:31
  • well im totaly lost for some reason if i try to query jobs and failed_jobs : **DB::connection('connection_B')->table('jobs')->get();** i get the error table jobs not found **DB::connection('connection_B')->table('my-schema.jobs')->get();** works **DB::connection('connection_B')->table('failed_jobs')->get();** works without mentioning the schema and in my connection_B i have set the right schema. any idea whats going on why lumen cant find jobs table without forcing the schema ? – Mr.Sef Aug 14 '21 at 11:30

1 Answers1

0

i solved the issue in the queue.php

'connections' => [
    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
        'connection' => 'connection_B', // this works
    ],

im blind idiot i typed connnection with 3n , i also cleared the cache and cache config i dont know if it helped or not.

Thank you.

Mr.Sef
  • 49
  • 1
  • 4