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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Unable to cleanup value stream in loop

satish
1-Newbie

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

12 REPLIES 12
paic
1-Newbie
(To:satish)

Did you try this using the Immediate option?

satish
1-Newbie
(To:paic)

No Pai. Immediate option was set to false. Also once I receive error, I can not even purge manually by calling purge for each individual property. I simply have to drop value stream and recreate to cleanup data.

Sent from my iPhone

paic
1-Newbie
(To:satish)

I would try this with Immediate set to true, it is there for this type of use case I believe.

If you get 'hung up' you should re-start Tomcat to flush the memory and you should be able to continue.

qn
1-Newbie
1-Newbie
(To:satish)

Also, you can create a service "Delete" for the ThingTemplate which calling PurgePropertyHistory, with ​Immediate​ option, for each property.

Well I already did this approach, a Delete on ThingTemplate that automatically deletes all the History on value streams logged properties, the problem it's that if you right away after purging the History you try to Delete the Thing in itself it fails ( Support Case: 12784893​ ).

I think, TW should automatically delete Value Streams Logged properties when you delete the thing, it's a non sense on left not accessible data on the Value Stream ( data integrity! ).

Carles.

pause can help perhaps, if it is a timing issue.

Hi Pai,

It's not a Timing issue, I've already tried with pause, and other tricky ways, it's a transactional problem.

Carles.

chichen
5-Regular Member
(To:satish)

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;

//Your code here

   

    var params = {

propertyName: row.name /* STRING */,

endDate: endDate /* DATETIME */,

immediate: true /* BOOLEAN */,

startDate: startDate /* DATETIME */

    };

me.PurgePropertyHistory(params);

}

qn
1-Newbie
1-Newbie
(To:chichen)

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 !

chichen
5-Regular Member
(To:qn)

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.

qn
1-Newbie
1-Newbie
(To:chichen)

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.

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;

  }

Top Tags