cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2743
Views
5
Helpful
2
Replies

How do I increase the timeout for actions?

Mark Swanborough
Cisco Employee
Cisco Employee

A common question from developers building actions.

When executing an action, the following error is seen:

admin@ncs> request services service example my-long-running-action
Error: application timeout
[error][2017-03-10 11:22:16]

admin@ncs>

And in the log (for Java):

<ERROR> 10-Mar-2017::11:22:16.871 Dp NCS-DpMUX-18-example:APprovider: -
com.tailf.conf.ConfException: unexpected end of file
    at com.tailf.conf.ConfInternal.readFill(ConfInternal.java:415)
    at com.tailf.conf.ConfInternal.termRead(ConfInternal.java:185)
    at com.tailf.conf.ConfInternal.termRead(ConfInternal.java:113)
    at com.tailf.dp.Dp.read(Dp.java:1728)
    at com.tailf.ncs.ctrl.NcsDpMux.run(NcsDpMux.java:175)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
    ... 6 more
<WARN> 10-Mar-2017::11:22:16.871 NcsDpMux NCS-DpMUX-18-example:APprovider: - Error in NcsDpMux
com.tailf.conf.ConfException: unexpected end of file
    at com.tailf.conf.ConfInternal.readFill(ConfInternal.java:415)
    at com.tailf.conf.ConfInternal.termRead(ConfInternal.java:185)
    at com.tailf.conf.ConfInternal.termRead(ConfInternal.java:113)
    at com.tailf.dp.Dp.read(Dp.java:1728)
    at com.tailf.ncs.ctrl.NcsDpMux.run(NcsDpMux.java:175)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
    ... 6 more
<ERROR> 10-Mar-2017::11:22:16.872 NcsMain NCS-DpMUX-18-example:APprovider: - Received exception from package 'example' Message: 'unexpected end of file'

Where do you increase the timeout?

1 Accepted Solution

Accepted Solutions

Mark Swanborough
Cisco Employee
Cisco Employee

Action time outs are managed inside the action code (unlike service timeouts).

Here's an example to extend the action timeout. You can call this multiple times to extend the timeout (e.g. if you loop through some long running actions, in a simplistic scenario it might make sense to increase the timeout for each action).

    private static final int TIMEOUT_IN_SEC = 420; // 7 * 60

    public ConfXMLParam[] longRunningAction (DpActionTrans trans, ConfTag name,
                                                   ConfObject[] reverseKeyPath,
                                                   ConfXMLParam[] params)
            throws DpCallbackException {
       
        try {
           trans.actionSetTimeout( TIMEOUT_IN_SEC );
        }
        catch ( IOException ioe ) {
            throw new DpCallbackException( "IOException in setting Action timeout", ioe );
        }
        //Rest of code
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Similarly in Python:

class LongRunningAction(Action):
    @Action.action
    def cb_action(self, userInfo, name, kp, input, output):
        _ncs.dp.action_set_timeout(userInfo,240)‍‍‍‍‍‍‍‍‍
        #Rest of code‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies 2

Mark Swanborough
Cisco Employee
Cisco Employee

Action time outs are managed inside the action code (unlike service timeouts).

Here's an example to extend the action timeout. You can call this multiple times to extend the timeout (e.g. if you loop through some long running actions, in a simplistic scenario it might make sense to increase the timeout for each action).

    private static final int TIMEOUT_IN_SEC = 420; // 7 * 60

    public ConfXMLParam[] longRunningAction (DpActionTrans trans, ConfTag name,
                                                   ConfObject[] reverseKeyPath,
                                                   ConfXMLParam[] params)
            throws DpCallbackException {
       
        try {
           trans.actionSetTimeout( TIMEOUT_IN_SEC );
        }
        catch ( IOException ioe ) {
            throw new DpCallbackException( "IOException in setting Action timeout", ioe );
        }
        //Rest of code
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Similarly in Python:

class LongRunningAction(Action):
    @Action.action
    def cb_action(self, userInfo, name, kp, input, output):
        _ncs.dp.action_set_timeout(userInfo,240)‍‍‍‍‍‍‍‍‍
        #Rest of code‍‍‍‍‍‍‍‍‍‍

Good for our Knowledge Base!

In addition to that, users can find working example from here. FYI.

$NCS_DIR/examples.ncs/getting-started/developing-with-ncs/2-actions/packages/actions/src/java/src/com/example/actions/ActionCb.java