Store queued events in default connection
njansenNL opened this issue · 8 comments
Hi,
I'm trying to store the queued events in the main connection (jobs table) while i'm in the tenant-connection. I've tried purging the tenant, so the main connection is established. However an error is triggered that the jobs table doesn't exist in the tenant database.
SQLSTATE[42S02]: Base table or view not found: 1146 Table '<tenant_database>.jobs' doesn't exist (SQL: insert into `jobs` (`queue`, `payload`....
Can you help me fixing this issue?
Any suggestions?
Anyone?
Can you include some sample code?
Before creating the event, purge the tenant-connection:
$resolver = app('LeeMason\Tenantable\Resolver');
$tenant = $resolver->getActiveTenant();
$resolver->purgeTenantConnection();
Event::fire(new TransactionsCreated($_transactions));
Somehow, it keeps the tenant-connection and raises the error that the jobs-table isn't found
does the TransactionsCreated event get queued by implementing ShouldQueue?
do you queue an event within the event class? posting that event class would help as well.
Yes the TransactionsCreated event implements ShouldQueue, inside this event we don't create a new queued event:
<?php
namespace App\Listeners\Transactions;
# Models
use App\Worker;
use App\Transaction;
use App\Subscription;
# Events
use App\Events\TransactionsCreated;
use Illuminate\Contracts\Queue\ShouldQueue;
class NotifyWorkerWithNewTransactions implements ShouldQueue
{
/**
* Create the event listener.
*
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param TransactionsCreated $event
* @return boolean
*/
public function handle(TransactionsCreated $event)
{
# Fetch the resolver class either via the app() function or by injecting
$resolver = app('LeeMason\Tenantable\Resolver');
# Get the active tenant
$tenant = $resolver->getActiveTenant();
# Fetch the subscription name from the tenant
$subscription_name = explode('.', $tenant->domain);
# Close the tenant-connection
$resolver->purgeTenantConnection();
# Retrieve the subscription based on the extracted name
$subscription = Subscription::byName($subscription_name[0])->first();
// Query some data from the main-connection, execute Guzzle-request and handle response etc..
}
}
Any progress?
Hmm, I just tried it again and it seems to work now.. Thnx for any research / help on this issue!