Skip to content

Commit

Permalink
Test scheduled tasks on server
Browse files Browse the repository at this point in the history
  • Loading branch information
rjackson committed Apr 7, 2024
1 parent bd00147 commit 6c78ad2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
48 changes: 48 additions & 0 deletions app/Console/Commands/TestScheduledTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace BB\Console\Commands;

use BB\Helpers\TelegramHelper;
use Illuminate\Console\Command;

class TestScheduledTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:scheduled-task';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Testing scheduled tasks on server';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$telegram = new TelegramHelper("Test Scheduled Task");

$telegram->notify(
TelegramHelper::JOB,
"✔️ Test Scheduled Task successfully ran (notification from within task)"
);
}
}
13 changes: 12 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel
Commands\CreateTodaysSubCharges::class,
Commands\BillMembers::class,
Commands\CheckDeviceOnlineStatuses::class,
Commands\TestScheduledTask::class,
];


Expand All @@ -33,7 +34,6 @@ protected function schedule(Schedule $schedule)
{
$telegram = new TelegramHelper("createSubscriptionCharges");


$schedule
->command(Commands\CheckMembershipStatus::class)
->dailyAt('06:00')
Expand Down Expand Up @@ -69,5 +69,16 @@ protected function schedule(Schedule $schedule)
$message
);
});

$schedule
->command(Commands\TestScheduledTask::class)
->hourly()
->then(function($result) use ($telegram) {
$message = "✔️ Test Scheduled Task successfully ran (notification from 'then' hook)";
$telegram->notify(
TelegramHelper::JOB,
$message
);
});
}
}

0 comments on commit 6c78ad2

Please sign in to comment.