agritheory / shipstation_integration

Other
6 stars 6 forks source link

Refactor queue to use dedicated queue #14

Closed agritheory closed 5 months ago

fproldan commented 5 months ago

@agritheory

To add a custom queue we need to edit the common_site_config.json by adding the workers key, for instance:

"workers": {
  "shipstation": {
   "timeout": 8000
  }
} 

This will require running bench setup production or bench setup supervisor to the supervisor.conf file to be updated.

Then we need to edit the desired frappe.enqueue to use that queue instead of long:

frappe.enqueue(
    method="shipstation_integration.orders.list_orders",
    queue="shipstation",
)

I think that given it's a per bench/server configuration we need to find a way to make the usage of a custom queue configurable.

agritheory commented 5 months ago

@fproldan Do you think we should have this function like this programmatically, where the Shipstation Settings object modifies frappe.conf?

fproldan commented 5 months ago

@agritheory
The frappe.conf could be edited programmatically, I'm not sure if we can do the same for the bench setup supervisor part.

import os
sites_path = os.getcwd()
common_site_config_path = os.path.join(sites_path, 'common_site_config.json')
workers = frappe.conf.workers
if workers:
    workers['shipstation'] =  {'timeout': 8000}
else:
    workers = {'shipstation': {'timeout': 8000}}    
update_site_config('workers', workers, validate=False, site_config_path=common_site_config_path)

Another option that comes to mind is to allow to configure a custom queue name in Shipstation Settings and we use that one in our enqueue using long as a fallback if it's not configured, but the setup part of adding the queue should be mane manually.

agritheory commented 5 months ago

So Frappe does the supervisor config programmatically, I think it makes sense to configure this in an after_install hook or a patch. Given that we'll be reusing this approach in a couple of different apps, I think it would be good to establish a reliable pattern for configuring it.