Skip to main content
12-Amethyst
February 9, 2025
Solved

service some times doesn't work

  • February 9, 2025
  • 3 replies
  • 755 views

Hi, 

I am having a strange issue here that I don't know how to investigate,

 

I created thingshape then a template that has this thingshape, then I created 7 things driven from this template.
inside the thingshape i have a subscription that calls a service within the same thing shape, lets call it service 1 , this service 1 do some calculation and then calls service 2 and service 3 ,
the issue is: 
service 1 and 2 works fine on all the 7 things with no issues, but service it is rarely works for all the 7 things, most of the time works for one or two things only,

I tried to check the script log errors but nothing there, and when i run this service manually inside the thing it works fine with no issues.
I don't know what should i share else but the issue is not related to whatever the code written in any of the services (from my testing).

thanks

Best answer by IA_10816220

ok, 
for clarification, service 1 send some data to service 2, and service 2 write these data in the database and then call service 3 that go and get these data from the database and put it in an infotable, 

 

i belive the issue was that: while service 2 send the command or the query to write the data there should be some time delay for this data to be stored properly in the database before another service to go fetch it, so what i did is a some kind of a delay function like the code attached, to tell service 3 to hold on for a couple of seconds before going to fetch the data from the database.

it works fine for me now

logger.warn(me.name + ".FetchDataForMashupHelperDaily started");
var ms = 5000;
let start = new Date().getTime();
let end = start;
while (end < start + ms) {
	end = new Date().getTime();
}

 

3 replies

Rocko
19-Tanzanite
February 10, 2025

Well you could add what Thingworx version you are using, the frequency of the timer and the duration of the services called.

Also read this and maybe try an alternative implementation. https://community.ptc.com/t5/IoT-Tips/Timers-and-Schedulers-Best-Practice/ta-p/820215#M1077

 

Instead of subscribing many things to the same event (by interitance in this case), you could subscribe just the template and the iterate over its implementation.

 

16-Pearl
February 10, 2025

I guess there might be a typo in your description "service 1 and 2 works fine on all the 7 things with no issues, but service it is rarely works for all the 7 things, most of the time works for one or two things only". I guess you might mean the "service 3" doesn't work well for all the 7 things.

There are multiple reasons that the service doesn't work as expectation, it will be helpful to understand the issue if you can provide the related entities and the reproduce steps.

IA_1081622012-AmethystAuthorAnswer
12-Amethyst
February 12, 2025

ok, 
for clarification, service 1 send some data to service 2, and service 2 write these data in the database and then call service 3 that go and get these data from the database and put it in an infotable, 

 

i belive the issue was that: while service 2 send the command or the query to write the data there should be some time delay for this data to be stored properly in the database before another service to go fetch it, so what i did is a some kind of a delay function like the code attached, to tell service 3 to hold on for a couple of seconds before going to fetch the data from the database.

it works fine for me now

logger.warn(me.name + ".FetchDataForMashupHelperDaily started");
var ms = 5000;
let start = new Date().getTime();
let end = start;
while (end < start + ms) {
	end = new Date().getTime();
}