RajeshDhiman - Friday, March 29, 2013 2:58 AM:
I am writing a server method to do some complex processing which will take LONG time (I dont know how much time). In starting of method, I want to update a field of a table so that any one out side this method know that i am busy doing some complex number crunching. I am using applySQL() to update the feild as below. Once applySQL() is done, updated feild is not seen until server method returns doing all complex task. Please let me know if i am doing right way. I am stuck up in this. string sql =" BEGIN TRAN T1;"; // Now I am doing my long task return this;
sql +=" update [innovator].[My_Table] set status='busy' where id='32 char GUID' ";
sql +=" COMMIT TRAN T1;";
innovator.applySQL(sql); // Here I want to let the world that i am doing long running task
System.Threading.Thread.Sleep(600000);
Eric Domke - Tuesday, April 2, 2013 9:05 PM:
I am fairly certain that Aras also runs server methods under a transaction. Therefore, my hunch is that you are simply creating a transaction within a transaction which does not really get committed until the outer transaction (around the method) is committed. Perhaps you could get around this by having the server method set a flag in the database and then have a scheduled job on the server look for that flag and execute the long running code, clearing the flag when it is done.
RajeshDhiman - Wednesday, April 3, 2013 1:30 AM:
Hi Erric, I apprieciate your reply.
I am suspecting the same reason what you told about transactions. For Scheduler consider this scenario. My scheduler has been scheduled for 5 minutes interval (assume cannot change that), But my method takes indeterminate time to execute based on data it process, it can go beyond 5 minutes. In that case I dont want my method to pick same item again for processing in new run, which eariler run is already processing it.
Aras support has suggested to use application state variables. That is working too, but I believe that for good design we should avoid any application level variables, otherwise application may get bloated with global variables during long run.
Eric Domke - Wednesday, April 3, 2013 10:29 PM:
A couple of options:
1) If your scheduled task is an independent program (e.g. a C# console application), and not a server method, then you could have a three-state flag on the record. For the sake of discussion, consider the states as 0, 1, and 2. A record marked 0 is ignored by the program. When the trigger happens, a server event marks relevant records with a 1. The scheduled task looks for records marked with a 1 and marks them as a 2 to indicate it is processing it. (This would work in an independent program since you would not be under the transaction constraint). When the processing is done, clear the flag.
2) In the server method, create a new Innovator object (IOMFactory.CreateHttpConnection, and IOMFactory.CreateInnovator). This new Innovator object will not be subject to the transactional constraints that the default one passed in to the server method has. If you want to log in with the same credentials as the current user, you can sniff out the user's credentials from the HTTP headers by using CCO.Request.