From cdd71d60e8dd91d34c67acd67c5ca1b3173bf927 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Jan 2023 11:38:36 +1100 Subject: [PATCH] fixes for tests --- app/Jobs/Util/WebhookHandler.php | 38 +++++++++++++++++------ tests/Feature/Scheduler/SchedulerTest.php | 3 +- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 46dc23045bc8..25b63436f044 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -77,15 +77,13 @@ class WebhookHandler implements ShouldQueue $subscriptions = Webhook::where('company_id', $this->company->id) ->where('event_id', $this->event_id) - ->get(); - - if (! $subscriptions || $subscriptions->count() == 0) { - return; - } - - $subscriptions->each(function ($subscription) { + ->cursor() + ->each(function ($subscription) { + $this->process($subscription); + }); + } private function process($subscription) @@ -130,9 +128,27 @@ class WebhookHandler implements ShouldQueue $this->company ); - // if ($response->getStatusCode() == 410) - // return true; $subscription->delete(); + if ($response->getStatusCode() == 429){ + nlog("429 retry after 10 seconds internally"); + sleep(10); + + $response = $client->post($subscription->target_url, [ + RequestOptions::JSON => $data, // or 'json' => [...] + ]); + + SystemLogger::dispatch( + array_merge((array) $response, $data), + SystemLog::CATEGORY_WEBHOOK, + SystemLog::EVENT_WEBHOOK_SUCCESS, + SystemLog::TYPE_WEBHOOK_RESPONSE, + $this->resolveClient(), + $this->company + ); + + } + } catch (\Exception $e) { + nlog("429 occurred in the expcetion handler"); nlog($e->getMessage()); SystemLogger::dispatch( @@ -158,6 +174,10 @@ class WebhookHandler implements ShouldQueue public function failed($exception) { + + sleep(2); + nlog(print_r($exception->getMessage(), 1)); + } } diff --git a/tests/Feature/Scheduler/SchedulerTest.php b/tests/Feature/Scheduler/SchedulerTest.php index 43495179e2dd..944bd6a1f567 100644 --- a/tests/Feature/Scheduler/SchedulerTest.php +++ b/tests/Feature/Scheduler/SchedulerTest.php @@ -250,8 +250,9 @@ class SchedulerTest extends TestCase $method = $reflectionMethod->invoke(new SchedulerService($scheduler)); $scheduler->fresh(); + $offset = $this->company->timezone_offset(); - $this->assertEquals(now()->addMonth()->format('Y-m-d'), $scheduler->next_run->format('Y-m-d')); + $this->assertEquals(now()->startOfDay()->addMonthNoOverflow()->addSeconds($offset)->format('Y-m-d'), $scheduler->next_run->format('Y-m-d')); }