#1 2019-05-10 14:36:35

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Executing a shell command with mORMot

Hello,
Suppose that I have a sqlite database on my linux server and deployed a mORMot based server (Exposing the sqlite database to the web using mORMot REST).
Is it possible that after sending a request to server, It process the request (manipulate data on the database ) and execute command or shell script after ??

Thanks.

Offline

#2 2019-05-11 14:14:28

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

Re: Executing a shell command with mORMot

Yes, just call the shell from the service code.
You can use RunProcess() from mORMotService.pas - it will work on all supported OS and compiler.

Of course, it won't be very efficient, since creating a process has a non negligeable cost.

Offline

#3 2019-05-11 14:29:11

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Executing a shell command with mORMot

Hi ab,

I need to synchronize data with an external api, a procedure that can last from minutes to hours depending on the amount of products the user has.

Due to this high time, I was thinking of running an external process to perform this job rather than using a thread on the server.

The request is received, it would return to the client that the procedure was started and execute the command.

In your opinion this would not be necessary? Could you leave this thread running "for hours" on the server?

Last edited by macfly (2019-05-11 14:29:26)

Offline

#4 2019-05-11 15:10:26

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

Re: Executing a shell command with mORMot

The RunProcess() has a wait/nowait option.
You can just launch an executable and let the REST server continue its work.

But I would rather use a dedicated background thread for communicating with the external API.

Offline

#5 2019-05-11 15:24:25

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Executing a shell command with mORMot

Thanks ab,

I'm going in this direction.

I created a TSQLWorker table where I monitor the execution of the process to pass to the client. The process notifies the progress to the server through an internal service.

Because they are long tasks, the progress query interval can be quite long.

Last edited by macfly (2019-05-11 15:25:16)

Offline

#6 2019-05-12 08:05:15

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Re: Executing a shell command with mORMot

OOOOOOOOhhhhh SUPpppppppperrrrr !!
I love mORMot really.
Thnks you .

Offline

#7 2022-10-21 08:17:52

Bsaidus
Member
From: Algeria
Registered: 2018-12-16
Posts: 50

Re: Executing a shell command with mORMot

ab wrote:

Yes, just call the shell from the service code.
You can use RunProcess() from mORMotService.pas - it will work on all supported OS and compiler.

Of course, it won't be very efficient, since creating a process has a non negligeable cost.

Hello Ab,
Is this response, also Valid for RemoteDB access, I mean, I use the RemoteDB technique offred by mORMot, so How can I execute command(s) after the server receive some data from the Client.
 
            ClientData  => SynDBRemote(TSQLDBServerRemote) => + Save data in DB
                                                                                                + ExecuteCmd

thanks you

Offline

Board footer

Powered by FluxBB