Is groovy programming language Synchronous or Asynchronous? - asynchronous

Can anybody tell? Is groovy a Synchronous or Asynchronous programming language.
It seems, It is Asynchronous but for confirmation i am asking it. I did not get any solution whether is it Synchronous or Asynchronous language on google.
Please tell me how to use groovy as synchronous in script I have below code which doesn't completes it execution and groovy executes next line of code.
def expCmp="expdp HR/HR#"+srcOrclName+" directory=Export DUMPFILE="+schema+".dmp LOGFILE="+schema+".log SCHEMAS="+schema+""
proc = expCmp.execute()
println("Data export started.")
The execution of below line doesn't completes and groovy executes next line which is println("Data export started.").
proc = expCmp.execute()
So How can I stop groovy until above command completes it should not execute next line of code.
If we can run groovy script as synchronous, please tell let me know and give one example which synchronous call of groovy script.
Note: Please don't write code using class. make sure it is groovy script only.
Thanks in advance.

So when you run (cleaned up a bit to make it more Groovy)
def expCmp="expdp HR/HR#${srcOrclName} directory=Export DUMPFILE=${schema}.dmp LOGFILE=${schema}.log SCHEMAS=${schema}"
def proc = expCmp.execute()
That creates a new shell process and runs it asynchronously.
To wait for it to finish, simply put:
proc.waitForProcessOutput()
before your line:
println "Data export finished."

Related

How do you a depends_on an async command (and make it trigger async as well) on buildkite?

I have an async trigger step in buildkite (e.g. I don't want it to block the rest of the pipeline). However, I want the next command to only execute if the async step passes. How can I configure this in buildkite?
Reading through the buildkite documentation not sure if this is possible. I don't see an async attribute for anything but a trigger step -- but I just want to execute a command.
https://buildkite.com/docs/pipelines/
I want the next command to only execute if the async step passes.
That sounds like what a non-async trigger does? i.e. Run the triggered build and, on success, run the next command step. Perhaps you need to remove async: true from the trigger step and have a wait step in between?

Mule - Batch Job sync or async

I have two batch jobs in differents flows. The first, do an Upsert in Salesforce and when it finish, it call to the second flow that has another batch job.
This image represents the flows:
But when I see the log on the console, sometimes the log of the second batch is mixed with the log of the first.
I get the feeling that the batch processes are asynchronous and the second batch is called even though the first batch is being processed.
Am I wrong? Should I pay attention to the order of the logs?
If I wanted it to be totally synchronous, what would be the best way?
Mule Batch is asynchronous, it is like fire and forget. If you want to call the second batch after first batch is completed, then invoke the second batch at 'On Complete' phase of first batch as shown in below picture.
If you want to do some function before invoking the second batch, then you need to use request-reply scope to make batch component synchronous.
Yes the batch job is asynchronous. As soon as the batch execute is triggered the flow will move on to the next event processor.
If batch job 2 needs to run after batch job 1 only, then you can use the on-complete phase of the first batch job to trigger some event to indicate the first has finished so that can be used to trigger the second batch job.
Alternatively If the batch jobs are related that closely you might be able to combine them into one using multiple batch steps

Delaying part of an R script inside of a loop

I'm executing a batch file inside an R script. I'd like to run this and another large section of the R script twice using a foreach loop.
foreach (i=1:2, .combine = rbind)%do%{
shell.exec("\\\\network\\path\\to\\batch\\script.ext")
*rest of the R script*
}
One silly problem though is that this batch file generates data and that data is connected to SQL Server localdb inside the loop. I thought at first that the script would execute the batch file, wait for it to finish and then move on. However, (seems obvious in hindsight) the script instead executes the batch file, tries to grab data that hasn't been created yet (because the file isn't finished running) and the executes the batch file again before it finishes the first time.
I've been trying to find away to delay the rest of the script from executing until the batch script has finished executing but have not come up with anything yet. I'd appreciate any insights anyone has.
Use system2 instead of shell.exe. system2 calls are blocking — meaning, the function waits until the external program has finished running. On most systems, this can be used directly to run scripts. On Windows, you may have to invoke rundll32 to execute a script:
cmd = c('rundll32.exe', 'Shell32.dll,ShellExecute', 'NULL', 'open', scriptpath)
system2(paste(shQuote(cmd), collapse = ' '))
Windows users may use shell, which by default has wait=TRUE, which will cause R to wait for its completion. You may choose whether or not to directly "intern" the result.
On unix-like systems, use system, which also defaults to wait=TRUE.
If your batch file simply launches another process and terminates, then it may need to be modified to either wait for completion or return a suitable process or file indicator that can be monitored.

How to stop hiredis command?

I am using hiredis library in my project. I'm using async API. I schedule a read command and wait for data. That works fine. However problem occurs when I try to close the connection - I call redisAsyncDisconnect, however the callback routine isn't called until I receive data.
Is it possible to cancel the read operation? How? Or is there a way how to force close the connection?
The answer is clear now - redisAsyncFree does what I need - stops all commands and calls redisAsyncDisconnect.

Catching a return code from a non-interactive R script execution

I need to launch in batch some R processes and I'd like to catch a return code from the scripting language to understand if the R process had or not a poblem in its execution.
Generally speaking what I need is:
EXEC "R batch processing"
IF RC<>0 THEN
EXEC recovery process
END
So my question is: could I exit from an R batch processing passing a return code to the caller?
Use the quit function in R, e.g. quit(status = 1) and then catch it in your batch script - you may need to google on how to do that in your scripting language.

Resources