cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
566
Views
5
Helpful
1
Replies

How to write NSO python action with multiple transactions

Hello,

I'm trying to write a python action in which I need to make two commit. For that I tried to open two write transaction separately. My python code look like this:

class Action(Action):
  @Action.action
  def cb_action(self, uinfo, name, kp, input, output, trans):
    # Open the first transaction
    with ncs.maapi.single_write_trans(uinfo.username, 'python') as t:
      root = ncs.maagic.get_root(t)
      #First transaction code ....
      t.set_comment("First commit")
      t.apply()
    # Open the second transaction
    with ncs.maapi.single_write_trans(uinfo.username, 'python') as t1:
      # Second transaction code ...
      t1.set_comment("Second commit")
      t1.apply()

The first commit take place successfully but the second one don't occur. I'm wondering why such behaviour is happenning and if there a way to fix it.

 

Thanks,

1 Reply 1

Nabsch
Spotlight
Spotlight

Hello ,


Can you provide us more detail about the error message that you get ?

 

By default action and service have a timeout 120 seconds . If after the 120 sec the action or service didn’t complete the execution . It will abort.

 

In your case try to add some logs to see how much every transaction take. For action you can change the timeout from your action code .I Think if you change the timeout it’s going to fix your issue.


Link to doc 

For the service , you need to change the default value in the CDB.