https://prefect.io logo
j

Jonathan Lowery

02/10/2021, 8:16 PM
Is there a (locking?) mechanism to make mapped tasks mutually exclusive at runtime? Use case is pulling data for an ETL from multiple sources and wanting to limit one task at a time attempting to insert to a target table. When the tasks run over each other trying to insert to the same table, it causes contention Architecture right now is: gather sources to poll for updates -> map(poll for updates) -> map(insert to db) I suppose one alternate approach would be feeding all the gathered tasks through a grouping task that sets them as upstream/downstream from one another based on target table?
c

Chris White

02/10/2021, 8:25 PM
There is a concept of locking on an individual tag basic in Prefect Cloud, as described here: https://docs.prefect.io/orchestration/concepts/task-concurrency-limiting.html
👍 1
j

Jonathan Lowery

02/10/2021, 8:43 PM
So within core is there a means to this or just in cloud?
c

Chris White

02/10/2021, 8:44 PM
No, nothing native; locking requires something to manage global state, and Core by itself is effectively stateless
👍 1
j

Jimmy Le

02/10/2021, 8:51 PM
What about flattening the update query so the inserts all run in sequence?
j

Jonathan Lowery

02/10/2021, 9:00 PM
I think something like that is what I'll shoot for. Just need to tinker with the best way to sequence them; I think in asking my question I formulated a potential solution to try
❤️ 1
a

ale

02/11/2021, 7:17 AM
@Jonathan Lowery another option is to use Prefect GraphQL client to run a query to check for running/submitted tasks. I've done this for flows and it works nicely. Not the best solution, because it add some complexity to the code, but it works simple smile Feel free to DM me and I can share more details
👍 1
3 Views