SYNCHRONIZATION ISSUE

  • 13 February 2013
  • 8 replies
  • 1 view

Badge +11

Hi


 


I had an issue in getting the current activity details for a process; so i went to the following link


http://forum.k2workflow.com/forums/p/12471/36524.aspx 


 


the problem is that the info for the activity is delayed for some time and after applying the Smart object solution and the Direct sql call to the k2serverlog database the problem persists.


what shall i do in order to FLUSH the changes of the process instance after executing the action.execute method.


--------------


 


 Connection conn = new Connection();


            //Connect to Workflow Server


            conn.Open(connSetup);


            // Get the WorklistItem object


            string sn = TextBox1.Text;


            // get the worklist item, and process instance (for data fields)


            WorklistItem wi = conn.OpenWorklistItem(sn);


            ProcessInstance pi = wi.ProcessInstance;


            // Set the Process Data Fields


 


            // execute the action


            wi.Actions[DropDownList1.Text].Execute();


//WHAT SHALL I DO TO MAKE SURE THAT THE DATA IS COMMITTED TO THE DATABASE


 


-------------


8 replies

Badge +13

I don't know how BP works behind the scenes when you execute the action.   Does it put it in a queue to be processed in order?  It's probably asynchronous.


In your activity, does it have other lengthy operations in the client event or server event attached to the activity?


Does it complete/commit within 10 seconds of execute?

Badge +11

Thanks peter for the reply


Actually it is synchronous. but as you said after the client event there is a smart object event that saves the comments written by the user. the smart object gets the comments from a comment datafield.


the process is completed/committed in less than 10 minutes.


 


 

Badge +8

Could you explain a bit more on what you are trying to achieve? Logging to the Log DB in K2 occurs async to ensure performance for real-time processing.


If you just need to wait for the first Client event to be completed before showing the second one, you can execute the action Synchronously. If not, let us know what you are trying to achieve in order for us to guide you better.

Badge +11

Well Mr DC here is the scenario


I have custom code in the preceding rule of every activity in the process; it fills a data field called ProcessInstanceStatus with a constant value for each activity.


here is a glimpse of the code in one of the preceding rules


-----------------------------------------------------------------------------



     public partial class PrecedingRule_917ede7a21cd47ef9cac919adc45e3f4 : IWorkflowContext<hostContext>


{


#region K2 Context 


{BLA Bla Bla}


        #endregion


 


#region IWorkflowContext<hostContext> Members


{BLA Bla Bla}


        #endregion


        private void codeActivity1_ExecuteCode(object sender, EventArgs e)


        {


            K2.PrecedingRule = K2.Configuration.Rule;


            K2.ProcessInstance.DataFields["ProcessInstanceStatus"].Value = "xxxxxx";


        }


}



--------------------------------------------------------------------------------------------------


NOW


- In the ASP.net code - After executing the Action.execute it is supposed that the process instance moves to the next activity, I call - from the asp.net - a smart object that executes the following statement:


SELECT * FROM Process_Data where
Dataname='ProcessInstanceStatus' and ProcessInstanceID={0}


This is supposed to return the value of the 'ProcessInstanceStatus' datafield at the activity. but what happens is that there is a delay in the retrieval and it brings the value of the previous activity.



what shall i do to retrieve the correct value?


I hope this is clear enough Mr. DC 

Badge +8

OK. There are two parts to a possible solution for you.


 



  1. Logging to the Log DB will always be async. So you will need another mechanism to store this value that allows for real-time retrieval. I would create a dedicated SmartObject for this, storing the Process Instance ID, this Status field you need and whatever other data  (like start date for example). So for the first Event in the Activity, you call this SmartObject and update the Status using the ProcInstID as primary key. This replaces your Preceding Rule code.
  2. In the ASP.NET page, you will first of all need to execute the Action Synchronous:
    wlItem.Actions[0].Execute(true);
    Once this returns control, you can call the SmartObject in your code and retrieve the latest value.

Just note that this will result in a performance loss from the user's perspective, as it will need to wait for all the processing on the K2 Server side to be completed. By default, actions are completed async so that the calling application gets focus as soon as possible.


 

Badge +11

Many thanks for your prompt Response Mr. DC


for point 1 ,  there is a problem with the status field; and it is as follows: I cant fill it from within the smart object and that is because each activity has more than one outcome to other activities and i don't know to which activity i will go till i execute the action. So having a code in the preceding rule is a must.


As for the other remarks i find them really helpful. Thanks a lot

Badge +8

There is no difference executing the SmartObject in the Preceding rule or as the first event in that Activity. So it seems that you might have misunderstood, this SmartObject should be executed from the destination activity, basically, it will replace your Preceding rule call.


Also, I made a typo in the write up, the client event needs to execute the Action sync, not async. The code sample is correct though.

Badge +11

sure I have misunderstood you twice :-). Async and the Smart object.


Thanks Mr. DC for your Great solution ... you are a life saver

Reply