fix: improve behavior when deleting mirrored record from farmOS
in some cases (maybe just dev?) the record does not exist in farmOS; if so we should silently ignore. and there seemed to be a problem with the sequence of events: - user clicks delete in WF - record is deleted from WF DB - delete request sent to farmOS API - webhook on farmOS side calls back to WF webhook URI somewhere in there, in practice things seemed to hang after user clicks delete. i suppose the thread handling user's request is "tied up" somehow, such that the webhook receiver can't process that request? that doesn't exactly make sense to me, but if we split off to a separate thread to request the farmOS deletion, things seem to work okay. so maybe that idea is more accurate than i'd expect
This commit is contained in:
parent
ca5e1420e4
commit
cc4b94a7b8
1 changed files with 19 additions and 2 deletions
|
|
@ -23,6 +23,9 @@
|
||||||
Base class for WuttaFarm master views
|
Base class for WuttaFarm master views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
import requests
|
||||||
from webhelpers2.html import tags
|
from webhelpers2.html import tags
|
||||||
|
|
||||||
from wuttaweb.views import MasterView
|
from wuttaweb.views import MasterView
|
||||||
|
|
@ -145,10 +148,24 @@ class WuttaFarmMasterView(MasterView):
|
||||||
|
|
||||||
# maybe delete from farmOS also
|
# maybe delete from farmOS also
|
||||||
if farmos_uuid:
|
if farmos_uuid:
|
||||||
|
client = get_farmos_client_for_user(self.request)
|
||||||
|
# nb. must use separate thread to avoid some kind of race
|
||||||
|
# condition (?) - seems as though maybe a "boomerang"
|
||||||
|
# effect is happening; this seems to help anyway
|
||||||
|
thread = threading.Thread(
|
||||||
|
target=self.delete_from_farmos, args=(client, farmos_uuid)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
def delete_from_farmos(self, client, farmos_uuid):
|
||||||
entity_type = self.get_farmos_entity_type()
|
entity_type = self.get_farmos_entity_type()
|
||||||
bundle = self.get_farmos_bundle()
|
bundle = self.get_farmos_bundle()
|
||||||
client = get_farmos_client_for_user(self.request)
|
try:
|
||||||
client.resource.delete(entity_type, bundle, farmos_uuid)
|
client.resource.delete(entity_type, bundle, farmos_uuid)
|
||||||
|
except requests.HTTPError as exc:
|
||||||
|
# ignore if record not found in farmOS
|
||||||
|
if exc.response.status_code != 404:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class TaxonomyMasterView(WuttaFarmMasterView):
|
class TaxonomyMasterView(WuttaFarmMasterView):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue