#1 2019-06-11 17:37:42

Shadownildo
Member
From: Brazil
Registered: 2018-10-10
Posts: 36

Timeout with TSQLHttpClient on Long Query

Hello Again smile

So, i'm having a little problem when I try to use a service and it takes longer than usual, I get an Exception from Time out, I know that with WebSocket i can do this, but I was wondering if there is a way to do this with httpSQLClient and httpSQLServer because I know it is not perfomatic or ideal that a query takes so long, but there will be cases that the internet may be slow in some report or something of the genre, it would not stop the Service, even if it takes a while, and i do not found anything that helps to do this in the forum and documentation ( i know Callbacks can work, but i'm trying to do without then). already try to use setTimeout with the Service but not work

 
 FactoryService := FRest.ServiceDefine(TVendaService, [IVendaService], sicClientDriven);
 FactoryService.SetTimeoutSec(99999999);       

Sorry about the Bad English
Best Regards,
Shadownildo

Offline

#2 2019-06-12 09:46:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,657
Website

Re: Timeout with TSQLHttpClient on Long Query

Just use a queue and a background thread, then two methods, like MyProcessStart and IsMyProcessFinished to pool the service.

Offline

#3 2019-06-13 13:50:31

Shadownildo
Member
From: Brazil
Registered: 2018-10-10
Posts: 36

Re: Timeout with TSQLHttpClient on Long Query

ab wrote:

Just use a queue and a background thread, then two methods, like MyProcessStart and IsMyProcessFinished to pool the service.

Thanks for The Answer Ab!

I'm sorry to ask this, but you have a Sample? because i can't visualize this suggestion and for me study this better ?

Offline

#4 2019-06-14 06:43:26

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: Timeout with TSQLHttpClient on Long Query

Check your http client constructor, there are some timeout parameters there you might find useful.

As for understanding what ab said, the service method that executes on the server side should not take long, in fact, it should exit as soon as possible. If you know that it will take a long time then move (or rather schedule) the work to a worker thread instead, this avoids blocking the connection thread that received your client request and as a result, solves the timeout issue.

This introduces a different problem, how will the client know when the work has finished processing? Pooling, which is basically about asking the server for the current work status, at some interval. For example, in your service definition "TVendaService" you would define a function like "function IsWorkFinished(WorkID : Integer) : Boolean", and on the client side, call this function every X ms/sec in a timer. This is just basic example,
typically you would include status codes instead "procedure IsWorkFinished(WorkID : Integer; out Status: Integer)", like "WORK_IS_QUEUED","WORK_IS_PROCESSING","WORK_FINISHED" etc..., you get the gist.

Offline

#5 2019-06-14 12:13:54

Shadownildo
Member
From: Brazil
Registered: 2018-10-10
Posts: 36

Re: Timeout with TSQLHttpClient on Long Query

pvn0 wrote:

Check your http client constructor, there are some timeout parameters there you might find useful.

As for understanding what ab said, the service method that executes on the server side should not take long, in fact, it should exit as soon as possible. If you know that it will take a long time then move (or rather schedule) the work to a worker thread instead, this avoids blocking the connection thread that received your client request and as a result, solves the timeout issue.

This introduces a different problem, how will the client know when the work has finished processing? Pooling, which is basically about asking the server for the current work status, at some interval. For example, in your service definition "TVendaService" you would define a function like "function IsWorkFinished(WorkID : Integer) : Boolean", and on the client side, call this function every X ms/sec in a timer. This is just basic example,
typically you would include status codes instead "procedure IsWorkFinished(WorkID : Integer; out Status: Integer)", like "WORK_IS_QUEUED","WORK_IS_PROCESSING","WORK_FINISHED" etc..., you get the gist.

Thanks For the Answer pvn0!

if i understand it right, it will work Like a CallBack ? that i have to a code like 

 Procedure IsWorking(const WorkID: Integer; Out Status :integer); 

that implements something like this

procedure IsWorking(WorkID : Integer; out Status: integer)
begin
if WorkId = 0 then
 break;
Status := Service.Work(workId); // Example 
end;

We are using ID to exemplify this , but How i get that ID or Name,and how i know is still Working? This part is a bit confusing for me, i understand i will have to create A Thread Pool, but how  Find the Same Work instance is what i don't know how

Sorry about fo the newbie questions and the Bad English hmm
Best Regards
Shadownildo

Offline

#6 2019-06-14 13:41:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,657
Website

Re: Timeout with TSQLHttpClient on Long Query

Tip: use an enumerate for the Status values, instead of an integer.

Offline

Board footer

Powered by FluxBB