Hi! I'm new to Prefect and was wondering what type...
# ask-community
l
Hi! I'm new to Prefect and was wondering what type of cleanup if any will Prefect perform on its own, how is this configured and where is it documented? I am interested in cleaning up a deployment and making sure anything that the deployment left in the database is removed
👀 1
n
hi @Li - welcome! are you using OSS prefect or Prefect Cloud? typically deleting a deployment will cascade delete a lot of related objects - the relations aren't prominently documented I don't believe, but you might find the orm models interesting if you're curious
l
Hi! Thanks for the reply. I have an on premise installation. I noticed that for example artifacts, logs and task state cache items are not deleted. What about those ?
n
artifacts, logs and task state cache items are not deleted
artifacts being kept around by default makes sense to me, sort of by definition, but im not so sure on the latter two. if you wanted to delete more things on deletion of a deployment that aren't already covered by our cascades, I think one could implement a util / simple service that looks up resources (like artifacts, logs etc) related to the deployment being deleted and deletes them - im not so sure on an what an exact implementation would look like off the top, but a simple place to start could be just using the client to write some function like
delete_deployment_and_associated_resources
that you call when you want your custom deletion behavior
l
we are developing stuff using prefect and for each feature we have a branch, we make deployments for that branch to run tests and then would like a clean teardown of everything related to that branch.
some of the objects don't have delete functions on the python SDK client. looking at the logs and task_state_cache ... do you have an advice on how to deal with those ?
n
some of the objects don't have delete functions on the python SDK client. looking ... do you have an advice on how to deal with those ?
yeah you can customize the client like
Copy code
from prefect.client.orchestration import PrefectClient

class MyPrefectClient(PrefectClient):
   async def delete_logs_for_deployment(self, deployment_id: uuid.UUID):
      pass

   ...
or open a PR if you think the methods would be generally useful
l
thanks, Nate!
n
👍