Multiple web requests


#1

Hello, When I have more then one web request, Webcore will pause for 20 sec. between each request. I am trying to send an down command to my Roku 4 time, but it is taking over 1 min for it to click down to the menu I want. Is there any way to make it so that it can send multiple web request at once?

I belive it has to do with:
“07/06/2017 >>> v0.2.0cf.20170706 - BETA M2 - Fix for parsing string date and times, implemented local http request response support - local web requests will wait for a response for up to 20 seconds - JSON response, if any, is available via $response”

Is there a way for me to disable this?

Thanks


#2

Try moving the web requests into individual Action blocks (multiple with Location do...) then on each action block you can use the :gear: icon to show more settings. Change the Execution Method to asynchronous. This should allow the web requests to run at the same time; you may want to add a short wait (e.g. 100ms on the second, 200ms on the third, etc) to keep them in order but it shouldn’t be necessary.

31 PM


#3

Actually, the above does not work. If I change the first to a request that takes a long time to respond, the second does not execute until after the response is received despite the async.

I am not aware of a way to instruct webCoRE to not wait up to 20 seconds for the response. So, here is an alternate approach that still uses a single piston. The piston calls itself multiple times to do the web requests.

The problem here is that if you try to run a piston more than 2 times in parallel the scheduled jobs are killed. When I ran this with 4 it only sent requests B and D. So I have it do requests A and B, then when each finishes they fire off C and D, respectively. In your situation this would lead to all the requests being made in about 20 seconds rather than a minute.

At the moment, it seems like the only way to send 4 requests at roughly the same time in webCoRE is to execute four pistons that each do one request or two pistons that take arguments and run in parallel, as shown above but with C and D split into a second piston.


Sending multiple web requests by expression
#4

Hello,

I was able to resolve it by modify line 3248
Old:
return 20000
New:
return 1000

Thanks


#5

Just be cautious since if you update webCoRE from GitHub your change will be lost. That is not the kind of change that would be published for everyone so you will need to apply the change again any time you update. Hopefully we can get a better solution for this in the future… either adjusting the timeout on each request or marking a request that just ignores the response.


#6

You have them in separate async blocks. So, they will run in series.


#7

This is incorrect; async blocks run in parallel with the rest of the piston, but statements within the block run in series. The following with two asynchronous blocks logs C A D B because the statements within each block execute in order.


#8

I have what I believe is a similar issue, as in, children pistons do not seem to do what I believe they are supposed to. My original thread is here: Passing variables through pistons. I have fixed the variable issue I was having, but the setup is still not working. Here are screenshots of both:
Master (caller):


Child (called piston that does the work):

I can also upload the logs, it’s basically turning the switches on correctly, but only one of them gets turned off. I am a newbie, but from what I can tell the execution is not parallelized.

Thanks!


#9

You can’t define the piston with the argument, that has to be in the action of the piston. When you “call” the other piston, you first have to set your variables and then pass those variables as arguments. You then need a statement setting your variable from the argument. Your definition section doesn’t perform the action. It merely displays the value of the variable. so, in your execute section, put in a “Set Variable” to argument then enter the argument name.


#10

It should be fine to use$args in the define section of the piston that gets executed. It may not work if you set the variable to constant but I use this pattern regularly with dynamic variables derived from args.


#11

Huh…I didn’t know that. When triggering one piston from another I always declared the set variable function at the top of the piston. So, we would need logs to see if any of the arguments are being passed over and that’s why your variables aren’t being set correctly and preventing piston from firing.


#12

to re-open an old wound, I wonder if using the wait parameter on the execute piston would have resolved this issue…