Laravel Vapor - Code sync from Shipping Portal, test run schedule tasks with logs

This commit is contained in:
Dillon Ngo
2023-12-31 03:50:16 +08:00
parent 5728017911
commit ff53e16ceb
4 changed files with 100 additions and 11 deletions
+4
View File
@@ -68,3 +68,7 @@ VOUCHERIFY_APPLICATION_ID=""
VOUCHERIFY_CLIENT_SECRET_KEY=""
VOUCHERIFY_VERSION="v2018-08-01"
VOUCHERIFY_URL="https://as1.api.voucherify.io"
LARAVEL_VAPOR_ENABLED=false
COMMANDS_V2_ENABLED=false
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class DummyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Dummy.');
$start = new Carbon();
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Dummy. ElapsedTime: ' . $elapsedTime . '.');
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\DummyJob;
use Illuminate\Console\Command;
class DummyCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'dummy-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'A test run at Laravel Vapor for schedule tasks run via dispatch a queued job';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('memory_limit', '-1');
DummyJob::dispatch();
}
}
+20 -11
View File
@@ -30,19 +30,28 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
//Commands Version 2: Laravel Vapor/AWS
$isEnabled = env('COMMANDS_V2_ENABLED', false);
if($isEnabled){
$schedule->command('dummy-command')
->everyFiveMinutes()
->withoutOverlapping();
}
//Commands Version 1: Before Laravel Vapor/AWS
else{
// $schedule->command('inspire')->hourly();
$schedule->command('mail:EmailDoToVTCommand')->dailyAt('10:00')->withoutOverlapping();
// $schedule->command('inspire')->hourly();
$schedule->command('mail:EmailDoToVTCommand')->dailyAt('10:00')->withoutOverlapping();
$schedule->command('seasonalSegmantCompany:remove')
->dailyAt('01:00')
->appendOutputTo(storage_path().'/logs/soft-delete-seasonal-segmant-company.log')
->withoutOverlapping();
$schedule->command('seasonalSegmantCompany:remove')
->dailyAt('01:00')
->appendOutputTo(storage_path().'/logs/soft-delete-seasonal-segmant-company.log')
->withoutOverlapping();
$schedule->command('delete:bulk-download-files')
->hourly()
->appendOutputTo(storage_path().'/logs/delete-bulk-download-files.log')
->withoutOverlapping();
$schedule->command('delete:bulk-download-files')
->hourly()
->appendOutputTo(storage_path().'/logs/delete-bulk-download-files.log')
->withoutOverlapping();
}
}
/**