Forum Discussion

CBleunven's avatar
CBleunven
Contributor
13 years ago

execution in parrallel of two functions

Hi,

I'm looking to automatically add a bug in tfs when an error occurs. For this I add an OnLogError event handler and use the IssueTracking object. This allows me to populate the various field of the bug report with the required values.

In order to centralize information at the maximum, I would like to add a copy of the Log with the error. But the log entry that regards the error will be added only after leaving the GeneralEvents_OnLogError(Sender, LogParams) method so the Log copy I can made (with Log["SaveResultsAs"]) at this point is not satisfying.



Is there a way to delay the addition of the log copy after the log entry has been added. something like this in "pseudo code"





function GeneralEvents_OnLogError(Sender, LogParams)



   //prepare the bug information

   item = IssueTracking["MyTemplate"]( blablabla );



   Start_in_parallel ( attachTheFile(item) );



   //immediately continue

}



function attachTheFile(item)

{

  Delay (1000); //like this the event will be treated until the end and the log entry added

  Log["SaveResultsAs"](logPath,lsMHT);

  item["AttachFile"](logPath);

}







I had a look to use NetworkSuite - Jobs - Task but I guess it's not really intended for this use and so it may be a problem to start the job on the same computer.



Thanks for help,



Christophe


  • Hi to all,

    I've delayed a bit this question for other priorities but I need now to come back on it.

    Use of job was unsuccessful. I go on another direction with Runner and start a method asynchronously but it is not successful too with the following code:



    function GeneralEvents_OnLogError(Sender, LogParams)

    {

       CallResultObj = Runner["CallObjectMethodAsync"](aToolToWriteLog, "createIssue", LogParams);

    }







    function createIssue(LogParams)

    {

      delay(10000);

      var message = LogParams["Str"];

      var priority = LogParams["Priority"] / 100;

      var severity = "3 - Medium";

      var buildNumber = "3";

      var description = LogParams["StrEx"];

      var logPath = "C:\\Temp\\Log.mht";

      var t = Log["SaveResultsAs"](logPath,lsMHT);

      var item = IssueTracking["TemplateN2"](message,priority,severity,buildNumber,description);

      item["AttachFile"](logPath);

    }





    What I observed is that script doesn't continue in the GeneralEvents_OnLogError method until the create issue is ended, and so the saved Log with the Issue tracking is not complete.



    Is there another way to solve this problem, as it is better, I guess that the Log saved with the issue include the error ?



    Thanks for help,



    Christophe



  • Hi Christophe,



    I think that you can set up a timer that will execute the required code after the error is posted. Please find more information on this in the Timer Object help topic.
  • Hi David,

    thank you for your suggestion.

    Unfortunately, it doesn't help as, if I stop the test execution, I stop the timer too and so the bug is never added to the database.

    I've found a workaround using the OnStopTest event.

    At the OnErrorEvent, I store the LogParameter object in a temporary variable.

    When the test end (I stop test item on error), I check if there was an error and if it is the case, I create the issue.



    thanks for help,

    Christophe