-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task Scheduler For Updating Delayed Projects
- Loading branch information
1 parent
07538bb
commit 62c81e2
Showing
7 changed files
with
184 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Enums\ProjectStatus; | ||
use App\Events\ProjectStatusUpdated; | ||
use App\Models\Project; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class UpdateDelayedProjectsStatus extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'projects:update-delayed'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update the status of delayed projects.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$pendingDelayedProjects = Project::where([ | ||
['deadline', '<', now()], | ||
['status', ProjectStatus::Pending], | ||
])->get(); | ||
|
||
foreach ($pendingDelayedProjects as $project) { | ||
$project->status = ProjectStatus::Delayed; | ||
$project->saveOrFail(); | ||
|
||
event(new ProjectStatusUpdated($project)); | ||
Log::info('Project Status Updated', ['project' => ['project_id' => $project->id, 'status' => $project->status]]); | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Project; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PrivateChannel; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProjectStatusUpdated | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(public Project $project) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the channels the event should broadcast on. | ||
* | ||
* @return array<int, \Illuminate\Broadcasting\Channel> | ||
*/ | ||
public function broadcastOn(): array | ||
{ | ||
return [ | ||
new PrivateChannel('project-status'), | ||
]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\ProjectStatusUpdated; | ||
use App\Mail\ProjectStatusUpdatedMail; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class NotifyAdminOnProjectStatusChange | ||
{ | ||
/** | ||
* Create the event listener. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(ProjectStatusUpdated $event): void | ||
{ | ||
Mail::to(User::admin()->first()) | ||
->send(new ProjectStatusUpdatedMail($event->project)); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\Project; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProjectStatusUpdatedMail extends Mailable implements ShouldQueue | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new message instance. | ||
*/ | ||
public function __construct(public Project $project) | ||
{ | ||
$this->project->load('client'); | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
*/ | ||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
subject: "Project Status Updated to {$this->project->status->name}", | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
*/ | ||
public function content(): Content | ||
{ | ||
return new Content( | ||
markdown: 'mail.project.status-updated', | ||
); | ||
} | ||
} |
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,26 @@ | ||
<x-mail::message> | ||
# Project Status Updated to {{ $project->status->name }} | ||
|
||
A project status has been updated since offered by {{ $project->client->name }} at {{ $project->created_at }}. | ||
|
||
Here's an overview of current status of the project: | ||
|
||
<x-mail::panel> | ||
**Project Name:** "{{ str($project->title)->limit(60, '...') }}" | ||
|
||
**Client Name:** {{ $project->client->name }} | ||
|
||
**Budget:** ${{ $project->budget }} | ||
|
||
**Last Updated:** {{ $project->updated_at }} | ||
|
||
**Deadline:** {{ $project->deadline }} ({{ $project->status->name }}) | ||
</x-mail::panel> | ||
|
||
<x-mail::button url="{{ route('projects.show', $project->slug) }}"> | ||
View Project | ||
</x-mail::button> | ||
|
||
Thanks,<br> | ||
{{ config('app.name') }} | ||
</x-mail::message> |