cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Programmatically add an action to background processing?

WM_9965332
11-Garnet

Programmatically add an action to background processing?

I have a piece of code I would like to have triggered in a background process programmatically once an action is clicked. Can it be done without a configuration change? Else what would be the best way to achieve this?  I also need to check if I can programmatically validate if my action is in the queue.

6 REPLIES 6
STEVEG
21-Topaz I
(To:WM_9965332)

I am not sure I can help with this one but I would like for you to give some more details.

Is this for a workflow or some other task?

What kind of action will trigger this process?

It can be for a workflow but for now the action, once triggered, generates a report and downloads it. I want this action to run in the background instead and send an email once it is complete. The action is triggered from an actions menu

I've done this by creating a process queue entry. I use listeners quite often to insert code based on system events like rename or check in.  The standard listener model works great but if you have cases where your custom code can throw exceptions, it can upset or break OOTB functions. My solution was to have the listener create a queue entry in a custom queue. This decouples the two actions and allows the normal PDMLink action to proceed normally. For example, I have a rename listener that adds a hook to when users rename Parts or CAD Docs. This creates a queue entry to propagate that rename to related items. So if they rename the WTPart, it syncs name with the CAD model or drawing.  Its designed in a way so that its stops and does not propagate forever.   Would this concept work for you?

I believe that concept can work. The goal is just to trigger my action in a queue and generate my report without impacting performance.

Here is some snippits. I have a class with some public methods that is serializable.

public class RenameJob implements Serializable {
    //private static PropertyResourceBundle props;
    private static Logger log=LogR.getLogger("RenameQueue");


    /**
     * Accept String values of object number, newName and type. Performs Rename
     * @param number
     * @param newName
     * @param objType
     * @throws java.lang.Exception, throw Exception with message back to QueueEntry
     */
    public static void doRename(String number, String newName, String objType) throws Exception
    {

and in my listener, I pass it the data to make the call to this method to do in a queue:

 private void createJob(String number, String newName, String objType)
    {
        try {
            ProcessingQueue queue=getQueue();
            if (queue != null)
            {
                Class[] types= {String.class, String.class, String.class};
                Object[] values = {number, newName, objType};
                queue.addEntry(SessionHelper.manager.getAdministrator(), "doRename", RenameJob.class.getName(), types , values);
            }
            else
                logger.debug("No available queue. Doing nothing.");
        }
        catch (WTException e)
        {
            logger.error("Error creating queueEntry to processRemoveAction.",e);
        }
    }

This adds the entry and tells it the class and method to run from the queue. Hope this helps.

Is it possible to see how this createJob function is called? All I want to do is have the entry call another method is execute my action. Also how would I check if a queue is already created if the user triggers the action more than once?

Top Tags