Skip to content

Add specific timeouts per request per #25 #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

PhillSimonds
Copy link

@PhillSimonds PhillSimonds commented Oct 17, 2024

This PR adds specific timeouts per request to the InfrahubClient and InfrahubNode objects per issue #25.

fixes #25

@PhillSimonds
Copy link
Author

I've added timeouts per what is outlined in #25.

The issue requests the addition of a timeout to the InfrahubClient's create() method. I added a timeout here as the method acquire a schema from the server in order to instantiate an InfrahubNode object in python memory.

This method creates an InfrahubNode object in python memory, but it does not make calls to the API to create the object on the server. From my understanding of the code, I would expect .create() on the client to call the API and create my Node -- but I may be misguided here. Can you confirm what's currently happening (no creation in the server) is the intended behavior of the InfrahubClient's .create() method?

@dgarros
Copy link
Contributor

dgarros commented Oct 18, 2024

Thanks @PhillSimonds, really appreciate the help with this PR

This method creates an InfrahubNode object in python memory, but it does not make calls to the API to create the object on the server. From my understanding of the code, I would expect .create() on the client to call the API and create my Node -- but I may be misguided here. Can you confirm what's currently happening (no creation in the server) is the intended behavior of the InfrahubClient's .create() method?

Yes this is the expected behavior for create currently,
Once you have the node "created" you can save it and then it will make the call to the API

obj = self.client.create(kind="BuiltinTag", name="Blue")
obj.save()

we should probably change the name for something more explicit

One of the main benefit of this approach is that we can use a batch to execute all the API calls in parallel

batch = await client.create_batch()
for tag in ["red", "green", "blue", "yellow", "orange"]:
     obj = client.create(kind="BuiltinTag", name=tag)
     batch.add(task=client.save)

async for obj, result in batch.execute():
    print(f"Tag {obj.name.value} created")

Having said that I totally see your point that someone might expect client.create() to actually create the object in infrahub, maybe we should add an option to control that (in a different PR). any thoughts from @opsmill/customer-success on this one ?

@ogenstad
Copy link
Contributor

Might be that the name is misleading and it should be client.create -> client.stage or similar.

@wvandeun
Copy link
Contributor

wvandeun commented Oct 18, 2024

Personally I like the workflow the way it is, ie you create the node in memory and then save it.
Which is aligned with how you update a node, you retrieve the node, make your changes and then save these changes.

That being said, I understand the point.
We could add an argument (save) to the create method, which defaults to False? But then you get a different workflow compared to updating a node.

device = client.create(InfraDevice, name="my device", save=True) 

But then we might as well add an argument that allows you to pass in a batch, to add the save action to a batch instead.

batch = client.create_batch()
device = client.create(InfraDevice, name="my device", save_with_batch=batch) 

An alternative could be to rename the create method. Maybe new_node or stage_node?

@PhillSimonds
Copy link
Author

Thanks @PhillSimonds, really appreciate the help with this PR...

Happy to help! Thanks for the clarifications :)

Copy link
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Phillip!

@ogenstad ogenstad merged commit be17bc3 into opsmill:develop Oct 23, 2024
10 checks passed
@PhillSimonds PhillSimonds deleted the ps-add-timeouts branch October 25, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: Add support for specific timeout per request
4 participants