tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 394 forks source link

New job are inserted in jobs table of system database instead of the current tenant one #725

Closed HpiGuillaume closed 5 years ago

HpiGuillaume commented 5 years ago

Description

When I've use the Queue management of Laravel v5.7.26 with Tenancy 5.x-dev, all new jobs were inserted in the jobs system table instead of jobs tenant table.


Information

I want queue on each tenant and, in plus, one for system. Purpose of those queue, manage mail.

Code I've use to insert in job:

$my_email_information = [
    "from" => "...",
    "to" => "...",
    ...
];

displatch(new myJob($my_email_information))
    ->onQueue('mail');

The job class:

...
class myJob implements ShouldQueue {
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $mail_informations = null
    public function __construct(array $data) { $this->mail_informations = $data; }
    public function handle () {
        ...
    };
}

By asking some help in the Discuss chat, @Plytas asking me to print the current tenant in handle method, and there was the good tenant displayed.

In the record in job table on system database, I've a "tenant_id:9" in the playload field (that are the good one too).

So don't understand why the record don't going into the good database.


tenancy.php config


use Hyn\Tenancy\Database\Connection;

return [
    'models' => [
        // Must implement \Hyn\Tenancy\Contracts\Hostname
        'hostname' => \Hyn\Tenancy\Models\Hostname::class,

        // Must implement \Hyn\Tenancy\Contracts\Website
        'website' => \Hyn\Tenancy\Models\Website::class,
    ],

    'middleware' => [
        // The eager identification middleware.
        \Hyn\Tenancy\Middleware\EagerIdentification::class,

        // The hostname actions middleware (redirects, https, maintenance).
        \Hyn\Tenancy\Middleware\HostnameActions::class,
    ],
    'website' => [
        'disable-random-id' => false,

        'random-id-generator' => Hyn\Tenancy\Generators\Uuid\ShaGenerator::class,

        'uuid-limit-length-to-32' => env('LIMIT_UUID_LENGTH_32', false),

        'disk' => null,

        'auto-create-tenant-directory' => true,

        'auto-rename-tenant-directory' => true,

        'auto-delete-tenant-directory' => false,

        'cache' => 10,
    ],
    'hostname' => [
        'default' => env('TENANCY_DEFAULT_HOSTNAME'),

        'auto-identification' => env('TENANCY_AUTO_HOSTNAME_IDENTIFICATION', true),

        'early-identification' => env('TENANCY_EARLY_IDENTIFICATION', true),

        'abort-without-identified-hostname' => env('TENANCY_ABORT_WITHOUT_HOSTNAME', false),

        'cache' => 10,

        'update-app-url' => false,
    ],
    'db' => [
        'default' => env('TENANCY_DEFAULT_CONNECTION'),

        'system-connection-name' => env('TENANCY_SYSTEM_CONNECTION_NAME', Connection::DEFAULT_SYSTEM_NAME),
        'tenant-connection-name' => env('TENANCY_TENANT_CONNECTION_NAME', Connection::DEFAULT_TENANT_NAME),

        'tenant-division-mode' => env('TENANCY_DATABASE_DIVISION_MODE', 'database'),

        'password-generator' => Hyn\Tenancy\Generators\Database\DefaultPasswordGenerator::class,

        'tenant-migrations-path' => database_path('migrations/tenant'),

        'tenant-seed-class' => false,

        'auto-create-tenant-database' => true,

        'auto-create-tenant-database-user' => true,

        'tenant-database-user-privileges' => 'SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER',

        'auto-rename-tenant-database' => true,

        'auto-delete-tenant-database' => env('TENANCY_DATABASE_AUTO_DELETE', false),

        'auto-delete-tenant-database-user' => env('TENANCY_DATABASE_AUTO_DELETE_USER', false),

        'force-tenant-connection-of-models' => [
        ],
        'force-system-connection-of-models' => [
        ],
    ],

    'routes' => [
        'path' => base_path('routes/tenants.php'),

        'replace-global' => false,
    ],

    'folders' => [
        'config' => [
            'enabled' => true,

            'blacklist' => ['database', 'tenancy', 'webserver'],
        ],
        'routes' => [
            'enabled' => true,

            'prefix' => null,
        ],
        'trans' => [
            'enabled' => false,

            'override-global' => true,

            'namespace' => 'tenant',
        ],
        'vendor' => [
            'enabled' => true,
        ],
        'media' => [
            'enabled' => true,
        ],
        'views' => [
            'enabled' => true,

            'namespace' => null,

            'override-global' => true,
        ],
    ],
];

queue.php config

...
    'default' => env('QUEUE_DRIVER', 'sync'),
    'connections' => [
        'sync' => [
            'driver' => 'sync',
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default',
            'retry_after' => 90,
        ],
...
ArlonAntonius commented 5 years ago

This has to do with Job Auto Tenancy we implemented in the dev branch. Provided possible solutions/things to think of through Discord, will be tested by @HpiGuillaume .

ArlonAntonius commented 5 years ago

@HpiGuillaume Can this be closed, did we provide you with enough information or is more info still needed?

HpiGuillaume commented 5 years ago

@ArlonAntonius sorry to not have tested since 6 days but I don't have time :/ I use only the system database now for my jobs so it's not blocking me. I prefer fix more blocking issue in my prod :)

I think it's bug, or just a mistake in my configuration files. I close with this message, but re-open when I've taking time to test the possible solution !