Multi tenancy email cronjob
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Multi tenancy email cronjob
Hello,
Version info:
Laravel - 8.x, PHP - 8.0, Aimeos - ~2023.07
I understand the order emails are sent using cronjob. But I have a multi-tenancy setup, what can I do to make the cronjob work for all tenant databases? So that it looks order status for all tenants and sends emails.
Version info:
Laravel - 8.x, PHP - 8.0, Aimeos - ~2023.07
I understand the order emails are sent using cronjob. But I have a multi-tenancy setup, what can I do to make the cronjob work for all tenant databases? So that it looks order status for all tenants and sends emails.
Re: Multi tenancy email cronjob
The jobs will be executed for all active sites in a multi-tenancy setup automatically.
Additionally, you can restrict executing a job to specific sites by adding the site codes as last parameter, e.g.:
Additionally, you can restrict executing a job to specific sites by adding the site codes as last parameter, e.g.:
Code: Select all
php artisan aimeos:jobs order/email/payment "default site2"
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Multi tenancy email cronjob
Thanks for the reply. By multi-tenancy, I mean I have multiple tenant databases. All tenant databases can have a single or multi-shop setup. The cronjob only seems to work for the database set in the .env file. How can I make the cronjob loop over all tenant databases?
Re: Multi tenancy email cronjob
If you have multiple databases, you also have multiple application instances. Then, you have to add the cronjobs for each application instance.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Multi tenancy email cronjob
I have a single application with multiple databases. Each database is set into config for use.
I am running the following code in a cron every minute.
And in the custom command,
But it takes the first database in loop and works only for that, not working for other DBs. Any help is appreciated.
I am running the following code in a cron every minute.
Code: Select all
$allTenants = Tenant::all();
foreach ($allTenants as $key => $tenant) {
config(['database.connections.user.database' => $databaseName]);
config(['shop.resource.db.database' => $databaseName]);
DB::purge('user');
DB::reconnect('user');
$sites = Site::select('code')->get();
if (!empty($sites)) {
$siteCodes = '';
foreach ($sites as $index => $site) {
$siteCodes .= $site->code;
if ($index < count($sites) - 1) {
$siteCodes .= ' ';
}
}
Artisan::call('aimeos:customjobs', [
'database' => $databaseName,
'jobs' => 'order/export/csv order/email/delivery order/email/payment order/email/voucher order/service/delivery subscription/export/csv customer/email/account',
'site' => $siteCodes,
]);
}
}
Code: Select all
protected $signature = 'aimeos:customjobs
{database : Tenant database name}
{jobs : One or more job controller names like "admin/job customer/email/watch"}
{site? : Site codes to execute the jobs for like "default unittest" (none for all)}
';
public function handle()
{
$jobs = $this->argument('jobs');
$jobs = !is_array($jobs) ? explode(' ', (string) $jobs) : $jobs;
$fcn = function (\Aimeos\MShop\ContextIface $lcontext, \Aimeos\Bootstrap $aimeos) use ($jobs) {
$jobfcn = function ($context, $aimeos, $jobname) {
\Aimeos\Controller\Jobs::create($context, $aimeos, $jobname)->run();
};
$process = $lcontext->process();
$site = $lcontext->locale()->getSiteItem()->getCode();
foreach ($jobs as $jobname) {
$this->info(sprintf('Executing Aimeos jobs "%s" for "%s"', $jobname, $site), 'v');
$process->start($jobfcn, [$lcontext, $aimeos, $jobname], false);
}
$process->wait();
};
$tenantDb = $this->argument('database');
config(['database.connections.mysql.database' => $tenantDb]);
config(['shop.resource.db.database' => $tenantDb]);
DB::purge('mysql');
DB::reconnect('mysql');
$this->exec($this->context(), $fcn, $this->argument('site'));
}
Re: Multi tenancy email cronjob
Guess, the artisan command is executed in a separate process and your changed in-memory config isn't used then.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star