fixes for tests

This commit is contained in:
David Bomba 2023-01-29 11:38:36 +11:00
parent 0630b9f757
commit cdd71d60e8
2 changed files with 31 additions and 10 deletions

View File

@ -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));
}
}

View File

@ -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'));
}