Merge pull request 'Added schedule method logic in app service provider' (#18) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
2025-11-29 05:35:04 +00:00
2 changed files with 163 additions and 87 deletions

View File

@@ -2,19 +2,19 @@
namespace App\Providers; namespace App\Providers;
use App\Models\AlertMailRule;
use App\Models\User; use App\Models\User;
use Filament\Facades\FilamentView;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use App\Policies\RolePolicy;
use App\Policies\PermissionPolicy; use App\Policies\PermissionPolicy;
use Spatie\Permission\Models\Role; use App\Policies\RolePolicy;
use Spatie\Permission\Models\Permission;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Assets\Js; use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Vite; use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
// use Doctrine\DBAL\Types\Type; // use Doctrine\DBAL\Types\Type;
@@ -28,7 +28,6 @@ class AppServiceProvider extends ServiceProvider
// //
} }
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*/ */
@@ -51,13 +50,13 @@ class AppServiceProvider extends ServiceProvider
FilamentAsset::register([ FilamentAsset::register([
Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(), Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
]); ]);
// if (env('APP_MODE') === 'admin') { // if (env('APP_MODE') === 'admin') {
// FilamentAsset::register([ // FilamentAsset::register([
// Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(), // Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
// ]); // ]);
// } // }
// URL::forceScheme('https'); // URL::forceScheme('https');
// if (!Type::hasType('citext')) { // if (!Type::hasType('citext')) {
@@ -70,5 +69,82 @@ class AppServiceProvider extends ServiceProvider
ini_set('max_execution_time', 300); // 300 seconds = 5 minutes ini_set('max_execution_time', 300); // 300 seconds = 5 minutes
ini_set('memory_limit', '512M'); // 512MB ini_set('memory_limit', '512M'); // 512MB
$schedule = app(Schedule::class);
$productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($productionRules as $rule) {
$type = $rule->schedule_type;
$plantId = $rule->plant;
$command = $schedule->command('send:production-report', [$type, $plantId]);
// ->appendOutputTo(storage_path('logs/scheduler.log'));
switch ($type) {
case 'Live':
$command->everyMinute();
break;
case 'Hourly':
$command->hourly();
break;
case 'Daily':
$command->dailyAt('07:59');
break;
}
}
// Invoice report scheduling
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($invoiceRules as $rule) {
$type = $rule->schedule_type;
$plantId = $rule->plant;
$command = $schedule->command('send:invoice-report', [$type, $plantId]);
switch ($type) {
case 'Live':
$command->everyMinute();
break;
case 'Hourly':
$command->hourly();
break;
case 'Daily':
$command->dailyAt('07:59');
break;
}
}
// Invoice Data Report Scheduling
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($invoiceDataRules as $rule) {
$type = $rule->schedule_type;
$plantId = $rule->plant;
$command = $schedule->command('send:invoice-data-report', [$type, $plantId]);
switch ($type) {
case 'Live':
$command->everyMinute();
break;
case 'Hourly':
$command->hourly();
break;
case 'Daily':
$command->dailyAt('10:00');
break;
}
}
} }
} }

View File

@@ -13,88 +13,88 @@ Artisan::command('inspire', function () {
// Schedule::command('send:invoice-report'); // Schedule::command('send:invoice-report');
// Schedule::command('send:production-report'); // Schedule::command('send:production-report');
app()->booted(function () { // app()->booted(function () {
$schedule = app(Schedule::class); // $schedule = app(Schedule::class);
// $schedule->command('report:send-daily-production')->dailyAt('07:59'); // // $schedule->command('report:send-daily-production')->dailyAt('07:59');
if (Schema::hasTable('alert_mail_rules')) { // if (Schema::hasTable('alert_mail_rules')) {
// Production report scheduling // // Production report scheduling
$productionRules = AlertMailRule::where('module', 'ProductionQuantities') // $productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail') // ->where('rule_name', 'ProductionMail')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($productionRules as $rule) { // foreach ($productionRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:production-report', [$type, $plantId]); // $command = $schedule->command('send:production-report', [$type, $plantId]);
// ->appendOutputTo(storage_path('logs/scheduler.log')); // // ->appendOutputTo(storage_path('logs/scheduler.log'));
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('07:59'); // $command->dailyAt('07:59');
break; // break;
} // }
} // }
// Invoice report scheduling // // Invoice report scheduling
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation') // $invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($invoiceRules as $rule) { // foreach ($invoiceRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:invoice-report', [$type, $plantId]); // $command = $schedule->command('send:invoice-report', [$type, $plantId]);
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('07:59'); // $command->dailyAt('07:59');
break; // break;
} // }
} // }
// Invoice Data Report Scheduling // // Invoice Data Report Scheduling
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport') // $invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($invoiceDataRules as $rule) { // foreach ($invoiceDataRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:invoice-data-report', [$type, $plantId]); // $command = $schedule->command('send:invoice-data-report', [$type, $plantId]);
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('10:00'); // $command->dailyAt('10:00');
break; // break;
} // }
} // }
} // }
}); // });