mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
wrap smart inv cache update w/ advisory lock
* Two job templates that use the same smart inventory running at the same time can easily race to recompute the smart inventory <-> host mapping. In this case, bulk_create() can throw an error when racing. * The per-smart-inventory advisory lock ensures that the state of the system is consistent & that bulk_create() runs in isolation.
This commit is contained in:
parent
e269634afc
commit
acb6d9c4d1
@ -602,6 +602,7 @@ def update_inventory_computed_fields(inventory_id, should_update_hosts=True):
|
||||
|
||||
|
||||
def update_smart_memberships_for_inventory(smart_inventory):
|
||||
with advisory_lock('update_smart_memberships_for_inventory-{}'.format(smart_inventory.id)):
|
||||
current = set(SmartInventoryMembership.objects.filter(inventory=smart_inventory).values_list('host_id', flat=True))
|
||||
new = set(smart_inventory.hosts.values_list('id', flat=True))
|
||||
additions = new - current
|
||||
|
Loading…
Reference in New Issue
Block a user