Updates for logging
This commit is contained in:
parent
18801c9809
commit
3c079bbe71
|
|
@ -33,6 +33,7 @@ use App\Models\TaxRate;
|
|||
use App\Libraries\MultiDB;
|
||||
use App\Models\TaskStatus;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\VendorContact;
|
||||
use App\Models\CompanyGateway;
|
||||
|
|
@ -600,8 +601,45 @@ class CreateSingleAccount extends Command
|
|||
$sub->frequency_id = RecurringInvoice::FREQUENCY_ANNUALLY;
|
||||
$sub->save();
|
||||
|
||||
|
||||
if($config = config('admin-api.products')){
|
||||
|
||||
foreach($config as $key => $product){
|
||||
|
||||
if(!$p = Product::where('product_key', $key)->first()){
|
||||
|
||||
$p = Product::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'product_key' => $key,
|
||||
'notes' => $product['description'],
|
||||
'price' => $product['price']
|
||||
]);
|
||||
|
||||
if(!Subscription::find($product['subscription_id'])){
|
||||
|
||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||
$sub->id = $product['subscription_id'];
|
||||
$sub->name = $product['description'];
|
||||
$sub->recurring_product_ids = "{$p->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->frequency_id = $product['term'] == 'month' ? RecurringInvoice::FREQUENCY_MONTHLY : RecurringInvoice::FREQUENCY_ANNUALLY;
|
||||
$sub->max_seats_limit = $product['users'] ?? 1;
|
||||
$sub->per_seat_enabled = true;
|
||||
$sub->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function createClient($company, $user)
|
||||
{
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2025. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\DataMapper\Analytics;
|
||||
|
||||
use Turbo124\Beacon\ExampleMetric\GenericMixedMetric;
|
||||
|
||||
class JobFailureAnalytics extends GenericMixedMetric
|
||||
{
|
||||
/**
|
||||
* The type of Sample.
|
||||
*
|
||||
* Monotonically incrementing counter
|
||||
*
|
||||
* - counter
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'mixed_metric';
|
||||
|
||||
/**
|
||||
* The name of the counter.
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'job.failed';
|
||||
|
||||
/**
|
||||
* The datetime of the counter measurement.
|
||||
*
|
||||
* date("Y-m-d H:i:s")
|
||||
*
|
||||
*/
|
||||
public $datetime;
|
||||
|
||||
/**
|
||||
* The Class failure name
|
||||
* set to 0.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $string_metric5 = 'name';
|
||||
public $string_metric6 = 'exception';
|
||||
|
||||
public $int_metric1 = 1;
|
||||
|
||||
public function __construct($string_metric5, $string_metric6)
|
||||
{
|
||||
$this->string_metric5 = $string_metric5;
|
||||
$this->string_metric6 = $string_metric6;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,25 +15,17 @@ namespace App\Jobs\RecurringInvoice;
|
|||
use App\Models\User;
|
||||
use App\Models\Company;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Events\Socket\RefetchEntity;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\Jobs\BaseJob;
|
||||
|
||||
class UpdateRecurring implements ShouldQueue
|
||||
class UpdateRecurring extends BaseJob
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public function __construct(public array $ids, public Company $company, public User $user, protected string $action, protected float $percentage = 0)
|
||||
{
|
||||
nlog("UpdateRecurring job constructed with IDs: " . implode(',', $ids) . " Action: {$action}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,8 +35,11 @@ class UpdateRecurring implements ShouldQueue
|
|||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
nlog("UpdateRecurring job STARTING - this proves it's being executed");
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
nlog("UpdateRecurring");
|
||||
$this->user->setCompany($this->company);
|
||||
|
||||
RecurringInvoice::query()->where('company_id', $this->company->id)
|
||||
|
|
@ -62,9 +57,32 @@ class UpdateRecurring implements ShouldQueue
|
|||
});
|
||||
|
||||
event(new RefetchEntity('recurring_invoices', null, $this->user));
|
||||
|
||||
nlog("UpdateRecurring job COMPLETED successfully");
|
||||
}
|
||||
|
||||
public function failed($exception = null)
|
||||
protected function getJobProperties(): array
|
||||
{
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
'action' => $this->action,
|
||||
'ids_count' => count($this->ids),
|
||||
'ids' => $this->ids,
|
||||
'percentage' => $this->percentage,
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleSpecificFailure(\Throwable $exception = null): void
|
||||
{
|
||||
nlog("UpdateRecurring specific failure handler called");
|
||||
if ($exception) {
|
||||
nlog("UpdateRecurring failed with: " . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function shouldDisableFailedJobStorage(): bool
|
||||
{
|
||||
return true; // Matches existing behavior
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2025. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Listeners\Job;
|
||||
|
||||
use App\DataMapper\Analytics\JobFailureAnalytics;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class GlobalJobFailureListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Handle the job failure event.
|
||||
*/
|
||||
public function handle(JobFailed $event): void
|
||||
{
|
||||
$name = $event->job->resolveName();
|
||||
$exception = $event->exception->getMessage();
|
||||
|
||||
Lightlogs::create(new JobFailureAnalytics($name, $exception))->send();
|
||||
}
|
||||
}
|
||||
|
|
@ -288,6 +288,8 @@ use App\Listeners\RecurringExpense\RecurringExpenseRestoredActivity;
|
|||
use App\Listeners\RecurringInvoice\RecurringInvoiceArchivedActivity;
|
||||
use App\Listeners\RecurringInvoice\RecurringInvoiceRestoredActivity;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use App\Listeners\Job\GlobalJobFailureListener;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -496,6 +498,9 @@ class EventServiceProvider extends ServiceProvider
|
|||
InvitationWasViewed::class => [
|
||||
InvitationViewedListener::class,
|
||||
],
|
||||
JobFailed::class => [
|
||||
GlobalJobFailureListener::class,
|
||||
],
|
||||
PaymentWasEmailed::class => [
|
||||
PaymentEmailedActivity::class,
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue