12 Replies Latest reply on Apr 4, 2016 7:41 AM by hpulkkinen RSS
    satish Explorer

    Unable to cleanup value stream in loop

    Hi,

     

    I have multiple properties of thing enabled for logging using value stream. after testing, I want to purge all properties value stream data. So I executed purgepropertyhistory for each property in loop. It does not work. I then notice below error in application error log.

     

    "Unable to process purgeBetweenNow Request for MoldMachineVars : Another request for this thing is active"

     

    Is there simple way of purging all properties valuestream data?

     

    Regards

    Satish

      • Re: Unable to cleanup value stream in loop
        paic Collaborator

        Did you try this using the Immediate option?

        • Re: Unable to cleanup value stream in loop
          chichen Explorer

          I found that the OOTB PurgePropertyHistory has limitations, you gotta input property name and end date.

          So I wrote a service like following code to clean all properties history during a given period.

           

          Service inputs: startDate, endDate (you must input endDate while testing the service)

           

          var params = {

          type: undefined /* BASETYPENAME */

          };

           

          // result: INFOTABLE dataShape: "PropertyDefinition"

          var LoggedPropertiesIT = me.GetLoggedProperties(params);

           

          var tableLength = LoggedPropertiesIT.rows.length;

           

          for (var x = 0; x < tableLength; x++) {

          var row = LoggedPropertiesIT.rows[x];

          //Your code here

             

              var params = {

          propertyName: row.name /* STRING */,

          endDate: endDate /* DATETIME */,

          immediate: true /* BOOLEAN */,

          startDate: startDate /* DATETIME */

              };

           

          me.PurgePropertyHistory(params);

          }

            • Re: Unable to cleanup value stream in loop
              qn Communicator

              I used this method, but I have a strange problem. "me.GetLoggedProperties(params)" give me a table of 20 properties (automatically in alphabetical order). Sometime, the last one is not purged. And the service blocks !

                • Re: Unable to cleanup value stream in loop
                  chichen Explorer

                  This service worked perfect for my case.

                  I put this service in ThingTamplate, and tested the service on several Thing instance.

                   

                  First, did GetLoggedProperties(params) returned the right logged properties infotable?

                  Second, you can try to test the OOTB PurgePropertyHistory service with the last property name and endDate input, see if it got problems.

                    • Re: Unable to cleanup value stream in loop
                      qn Communicator

                      Yes the service worked. But apparently, when I executed it many times consecutively, it would be a blocking thread when it took too much time. "PurgePropertyHistory service with the last property name and endDate input" did not work. Maybe it was the same problem as the one of this discussion.

                  • Re: Unable to cleanup value stream in loop
                    hpulkkinen Explorer

                    If someone is interested, I wrote a similar service in Java. It can be used for thing templates which are defined in extensions

                     

                     

                    /**

                      * Clears history from all logged properties.

                      * @return String containing list of cleared properties

                      * @throws Exception thrown by Thing.PurgePropertyHistory

                      */

                      @ThingworxServiceDefinition(name = "clearHistory", description = "Clears history from all logged properties.")

                      @ThingworxServiceResult(name = "result", description = "List of cleared properties.", baseType = "STRING")

                      public String clearHistory() throws Exception{

                      String result = "Cleared properties: ";

                      InfoTable LoggedPropertiesIT = this.GetLoggedProperties("");

                     

                     

                      for(int i = 0; i < LoggedPropertiesIT.getLength(); i++){

                      String propertyName = (String) LoggedPropertiesIT.getRow(i).getValue("name");

                      DateTime startDate = new DateTime(0); // 1.1.1970

                      DateTime endDate = new DateTime(); // Now

                      this.PurgePropertyHistory(propertyName, startDate, endDate, true);

                      result += propertyName + ", ";

                      }

                      result = result.substring(0, result.length()-2); // Remove last comma from the string

                      return result;

                      }