From 65267a92db927251a2f330aca30b0ea0e618cd6a Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 27 May 2021 23:45:36 +0300 Subject: [PATCH 1/5] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e14ceba1..27e20cec 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "funeralzone/valueobjects": "^0.5", "jenssegers/agent": "^2.6", "laravel/framework": "^7.0 || ^8.0", - "osiset/basic-shopify-api": "^9.0 || ^10.0" + "osiset/basic-shopify-api": "dev-master" }, "require-dev": { "ergebnis/composer-normalize": "^2.8", From bfb04d3b910dec02bac7cfb12e1a67edacb34ee9 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 3 Jul 2021 18:05:11 +0300 Subject: [PATCH 2/5] Now compressing the data sent to SQS --- src/ShopifyApp/Traits/WebhookController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ShopifyApp/Traits/WebhookController.php b/src/ShopifyApp/Traits/WebhookController.php index efbf179d..9a1c0fdd 100644 --- a/src/ShopifyApp/Traits/WebhookController.php +++ b/src/ShopifyApp/Traits/WebhookController.php @@ -2,6 +2,7 @@ namespace Osiset\ShopifyApp\Traits; +use App\Jobs\AbstractShopifyWebhookJob; use Illuminate\Http\Request; use Illuminate\Http\Response as ResponseResponse; use Illuminate\Support\Facades\Response; @@ -24,11 +25,10 @@ public function handle(string $type, Request $request): ResponseResponse { // Get the job class and dispatch $jobClass = getShopifyConfig('job_namespace').str_replace('-', '', ucwords($type, '-')).'Job'; - $jobData = json_decode($request->getContent()); $jobClass::dispatch( $request->header('x-shopify-shop-domain'), - $jobData + AbstractShopifyWebhookJob::compressPayload($request->getContent()) )->onQueue(getShopifyConfig('job_queues')['webhooks']); return Response::make('', 201); From 4009f32995fa7de1921ff619f8b6b7a77a895c79 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 3 Jul 2021 18:45:08 +0300 Subject: [PATCH 3/5] Update WebhookController.php --- src/ShopifyApp/Traits/WebhookController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShopifyApp/Traits/WebhookController.php b/src/ShopifyApp/Traits/WebhookController.php index 9a1c0fdd..750afb96 100644 --- a/src/ShopifyApp/Traits/WebhookController.php +++ b/src/ShopifyApp/Traits/WebhookController.php @@ -2,7 +2,7 @@ namespace Osiset\ShopifyApp\Traits; -use App\Jobs\AbstractShopifyWebhookJob; +use App\Jobs\ShopifyWebhooks\AbstractShopifyWebhookJob; use Illuminate\Http\Request; use Illuminate\Http\Response as ResponseResponse; use Illuminate\Support\Facades\Response; From e1eb3265f1cc6d5222fb842369d307cd55221b0a Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 9 Jul 2021 15:54:01 +0300 Subject: [PATCH 4/5] Hacking lib to accept DELAY_SECONDS --- src/ShopifyApp/Actions/DispatchWebhooks.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ShopifyApp/Actions/DispatchWebhooks.php b/src/ShopifyApp/Actions/DispatchWebhooks.php index f8ffa759..cf7883a4 100644 --- a/src/ShopifyApp/Actions/DispatchWebhooks.php +++ b/src/ShopifyApp/Actions/DispatchWebhooks.php @@ -66,10 +66,17 @@ public function __invoke(ShopIdValue $shopId, bool $inline = false): bool $webhooks ); } else { + if (defined("{$this->jobClass}::DELAY_SECONDS")) { + $delayTime = now()->addSecond(constant("{$this->jobClass}::DELAY_SECONDS")); + } else { + $delayTime = now(); + } + ($this->jobClass)::dispatch( $shop->getId(), $webhooks - )->onQueue(getShopifyConfig('job_queues')['webhooks']); + )->delay($delayTime) + ->onQueue(getShopifyConfig('job_queues')['webhooks']); } return true; From 96f7113010e0c21ff65d133a4355ebfde2b9b81b Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 9 Jul 2021 15:55:13 +0300 Subject: [PATCH 5/5] Hacking lib to accept DELAY_SECONDS --- src/ShopifyApp/Traits/WebhookController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ShopifyApp/Traits/WebhookController.php b/src/ShopifyApp/Traits/WebhookController.php index 750afb96..056cef45 100644 --- a/src/ShopifyApp/Traits/WebhookController.php +++ b/src/ShopifyApp/Traits/WebhookController.php @@ -26,10 +26,16 @@ public function handle(string $type, Request $request): ResponseResponse // Get the job class and dispatch $jobClass = getShopifyConfig('job_namespace').str_replace('-', '', ucwords($type, '-')).'Job'; + if (defined("{$jobClass}::DELAY_SECONDS")) { + $delayTime = now()->addSecond(constant("{$jobClass}::DELAY_SECONDS")); + } else { + $delayTime = now(); + } + $jobClass::dispatch( $request->header('x-shopify-shop-domain'), AbstractShopifyWebhookJob::compressPayload($request->getContent()) - )->onQueue(getShopifyConfig('job_queues')['webhooks']); + )->delay($delayTime)->onQueue(getShopifyConfig('job_queues')['webhooks']); return Response::make('', 201); }