-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement events for cron expenses; add processing of daily/monthly e…
…xpenses #136
- Loading branch information
Showing
24 changed files
with
623 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron; | ||
|
||
use App\Console\BaseCommand; | ||
use App\Events\CronMonthly; | ||
|
||
/** | ||
* This just calls the CronMonthly event, so all of the | ||
* listeners, etc can just be called to run those tasks | ||
* @package App\Console\Cron | ||
*/ | ||
class Monthly extends BaseCommand | ||
{ | ||
protected $signature = 'cron:monthly'; | ||
protected $description = 'Run the monthly cron tasks'; | ||
protected $schedule; | ||
|
||
public function handle(): void | ||
{ | ||
$this->redirectLoggingToStdout(); | ||
event(new CronMonthly()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron; | ||
|
||
use App\Console\BaseCommand; | ||
use App\Events\CronNightly; | ||
|
||
/** | ||
* This just calls the CronNightly event, so all of the | ||
* listeners, etc can just be called to run those tasks | ||
* @package App\Console\Cron | ||
*/ | ||
class Nightly extends BaseCommand | ||
{ | ||
protected $signature = 'cron:nightly'; | ||
protected $description = 'Run the nightly cron tasks'; | ||
protected $schedule; | ||
|
||
public function handle(): void | ||
{ | ||
$this->redirectLoggingToStdout(); | ||
event(new CronNightly()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron; | ||
|
||
use App\Console\BaseCommand; | ||
use App\Events\CronMonthly; | ||
|
||
/** | ||
* This just calls the CronWeekly event, so all of the | ||
* listeners, etc can just be called to run those tasks | ||
* @package App\Console\Cron | ||
*/ | ||
class Weekly extends BaseCommand | ||
{ | ||
protected $signature = 'cron:monthly'; | ||
protected $description = 'Run the monthly cron tasks'; | ||
protected $schedule; | ||
|
||
public function handle(): void | ||
{ | ||
$this->redirectLoggingToStdout(); | ||
event(new CronMonthly()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Monolog\Handler\StreamHandler; | ||
|
||
/** | ||
* Just a simple custom logger that dumps to the console | ||
* @package App\Console | ||
*/ | ||
class Logger | ||
{ | ||
public function __invoke(array $config) | ||
{ | ||
$logger = new \Monolog\Logger('console'); | ||
try { | ||
$logger->pushHandler(new StreamHandler('php://stdout')); | ||
} catch (\Exception $e) { | ||
} | ||
|
||
return $logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* This event is dispatched when the monthly cron is run | ||
* It happens after all of the default nightly tasks | ||
* @package App\Events | ||
*/ | ||
class CronMonthly | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* This event is dispatched when the daily cron is run | ||
* It happens after all of the default nightly tasks | ||
* @package App\Events | ||
*/ | ||
class CronNightly | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* This event is dispatched when the weekly cron is run | ||
* It happens after all of the default nightly tasks | ||
* @package App\Events | ||
*/ | ||
class CronWeekly | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Cron\Monthly; | ||
|
||
use App\Events\CronMonthly; | ||
use App\Models\Enums\ExpenseType; | ||
use App\Services\Finance\RecurringFinanceService; | ||
|
||
/** | ||
* Go through and apply any finances that are daily | ||
* @package App\Listeners\Cron\Nightly | ||
*/ | ||
class ApplyExpenses | ||
{ | ||
private $dfSvc; | ||
|
||
public function __construct(RecurringFinanceService $dfSvc) | ||
{ | ||
$this->dfSvc = $dfSvc; | ||
} | ||
|
||
/** | ||
* Apply all of the expenses for a month | ||
* @param CronMonthly $event | ||
* @throws \UnexpectedValueException | ||
* @throws \InvalidArgumentException | ||
* @throws \Prettus\Validator\Exceptions\ValidatorException | ||
*/ | ||
public function handle(CronMonthly $event) | ||
{ | ||
$this->dfSvc->processExpenses(ExpenseType::MONTHLY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Cron\Nightly; | ||
|
||
use App\Events\CronNightly; | ||
use App\Models\Enums\ExpenseType; | ||
use App\Services\Finance\RecurringFinanceService; | ||
|
||
/** | ||
* Go through and apply any finances that are daily | ||
* @package App\Listeners\Cron\Nightly | ||
*/ | ||
class ApplyExpenses | ||
{ | ||
private $dfSvc; | ||
|
||
public function __construct(RecurringFinanceService $dfSvc) | ||
{ | ||
$this->dfSvc = $dfSvc; | ||
} | ||
|
||
/** | ||
* Apply all of the expenses for a day | ||
* @param CronNightly $event | ||
* @throws \UnexpectedValueException | ||
* @throws \InvalidArgumentException | ||
* @throws \Prettus\Validator\Exceptions\ValidatorException | ||
*/ | ||
public function handle(CronNightly $event): void | ||
{ | ||
$this->dfSvc->processExpenses(ExpenseType::DAILY); | ||
} | ||
} |
Oops, something went wrong.