Skip to content

Commit

Permalink
Log job start (partial)
Browse files Browse the repository at this point in the history
Summary:
A way to log job execution.

I tried using Laravel event system to do this more magically (from one place),
but the events do not give easy access to job data.

Implemented only for User and Wallet jobs for now.

Reviewers: #hkccp_developers, mollekopf

Reviewed By: #hkccp_developers, mollekopf

Subscribers: mollekopf, #hkccp_developers

Differential Revision: https://git.kolab.org/D5001
  • Loading branch information
alecpl committed Nov 12, 2024
1 parent e28b0ec commit fde824a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/app/Jobs/CommonJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,12 @@ public function isReleased(): bool
{
return $this->isReleased;
}

/**
* Log human-readable job title (at least contains job class name)
*/
public function logJobStart($ident = null): void
{
\Log::info('Starting ' . $this::class . ($ident ? " for {$ident}" : ''));
}
}
2 changes: 2 additions & 0 deletions src/app/Jobs/User/CreateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CreateJob extends UserJob
*/
public function handle()
{
$this->logJobStart($this->userEmail);

$user = $this->getUser();

if (!$user) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/Jobs/User/DeleteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class DeleteJob extends UserJob
*/
public function handle()
{
$this->logJobStart($this->userEmail);

$user = $this->getUser();

if (!$user) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/Jobs/User/ResyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ResyncJob extends UserJob
*/
public function handle()
{
$this->logJobStart($this->userEmail);

$user = $this->getUser();

if (!$user) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/Jobs/User/UpdateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class UpdateJob extends UserJob implements ShouldBeUniqueUntilProcessing
*/
public function handle()
{
$this->logJobStart($this->userEmail);

$user = $this->getUser();

if (!$user) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/Jobs/User/VerifyJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class VerifyJob extends UserJob
*/
public function handle()
{
$this->logJobStart($this->userEmail);

$user = $this->getUser();

if (!$user) {
Expand Down
12 changes: 3 additions & 9 deletions src/app/Jobs/WalletCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

use App\Wallet;
use App\Http\Controllers\API\V4\PaymentsController;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;

class WalletCharge implements ShouldQueue
class WalletCharge extends CommonJob
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;

/** @var int How many times retry the job if it fails. */
public $tries = 5;

Expand Down Expand Up @@ -53,6 +45,8 @@ public function backoff(): array
*/
public function handle()
{
$this->logJobStart($this->walletId);

if ($wallet = Wallet::find($this->walletId)) {
PaymentsController::topUpWallet($wallet);
}
Expand Down
12 changes: 3 additions & 9 deletions src/app/Jobs/WalletCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@
use App\Http\Controllers\API\V4\PaymentsController;
use App\Wallet;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;

class WalletCheck implements ShouldQueue
class WalletCheck extends CommonJob
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;

public const THRESHOLD_DEGRADE = 'degrade';
public const THRESHOLD_DEGRADE_REMINDER = 'degrade-reminder';
public const THRESHOLD_BEFORE_DEGRADE = 'before-degrade';
Expand Down Expand Up @@ -65,6 +57,8 @@ public function backoff(): array
*/
public function handle()
{
$this->logJobStart($this->walletId);

$this->wallet = Wallet::find($this->walletId);

// Sanity check (owner deleted in meantime)
Expand Down

0 comments on commit fde824a

Please sign in to comment.