statamic-rad-pack / shopify

Integrate your Shopify products into Statamic using the Admin API.
https://statamic.com/addons/rad-pack/shopify
Other
8 stars 5 forks source link

Products getting duplicated on Webhook create/update event #239

Closed dgrigg closed 1 month ago

dgrigg commented 1 month ago

Description

Whenever a product is created in Shopify two duplicated items are getting created in Statamic. From Shopify I can see the 'create' and 'update' webhook both get sent right after product creation in Shopify. It's happening on our staging server which is using Redis for the queue. Locally I'm running the queue via the database and I don't have the duplication issue (using ngrok to receive incoming webhooks). I found this closed issue which looks similar https://github.com/statamic-rad-pack/shopify/issues/95 but that was closed 2 years ago and this issue is still popping up.

Screenshot 2024-09-24 at 12 07 27 PM

Steps to reproduce

  1. Create a new product in Shopify

Environment

Environment Application Name: Statamic Laravel Version: 10.48.22 PHP Version: 8.2.19 Composer Version: 2.7.6 Environment: local Debug Mode: ENABLED URL: localhost:3000 Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: file Database: mysql Logs: stack / single Mail: smtp Queue: database Session: file

Statamic Addons: 3 Sites: 1 Stache Watcher: Disabled Static Caching: Disabled Version: 5.25.0 PRO

Statamic Addons aerni/advanced-seo: 2.9.0 pxlp/headless: dev-main statamic-rad-pack/shopify: 4.0.3

ryanmitchell commented 1 month ago

Did you try the resolution from that issue of using a queue with only one worker?

ryanmitchell commented 1 month ago

Failing that the other option would be to only listen for the update webhook. We could update the docs to that effect.

dgrigg commented 1 month ago

Updating the supervisor settings to use 1 proc. Will let you know

dgrigg commented 1 month ago

Using 1 proc solved the issue. Ideally there's a way to make this work with multiple process, which is nice especially when dealing with bulk Shopify updates to products.

ryanmitchell commented 1 month ago

It would work fine with multi process if you remove the create webhook. By the looks of things shopify is firing the update when you create (strange but it is).

dgrigg commented 1 month ago

That's true

dgrigg commented 1 month ago

Can confirm that worked but it still feels dirty. If there's a way to prevent that from happening it would be great.