PHPAGI keeps the channel live - asterisk

I have a PHP script on extension h. I think extension h should be executed after call is finished, however when one of the parties hangup and AGI script is being executed - another party still can see the call as "active" until the script is finished processing.
In this scenario I need the script to perform some actions for 5 seconds, however for one of the parties call duration increases by 5 "fake" seconds:
[10:54:48] x.php: >>> [NOTICE] One of the parties hanged up <<<
[10:54:53] x.php: >>> [NOTICE] Script took 5 seconds <<<
[10:54:53] -- <SIP/from-sip-00000584>AGI Script x.php completed, returning 0
[10:54:53] == Spawn extension (from-sip, 123456789, 10) exited non-zero on 'SIP/from-sip-00000584'
Question: how to hangup both parties before running an AGI script?

That is expected behavour.
h extension is designed for logging, not for something that can take seconds. Also it can hangup script if it take too much(zombie prevention).
If you need do long-time actions after call is ended, correct way will be put in agi(better fastagi) script just code to log/prepair needed action(put info in temporary sql table or file).
After that you can do actions based on saved info in external daemon/script. As result every action can take hours without affection asterisk perfomance or calls

Related

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

Firebase cloud function with cron-job what happens if connection is closed while executing something

I want to know what happens if connection becomes nothing while executing some tasks for a Cloud Function.
cron-job.org says this:
You should design your scripts in a way that they send as little data as possible, ideally just a short status message at the end of the execution, e.g. "OK" — or simply nothing. In case your script is written in PHP and needs more than 30 seconds of run-time, you can use the following trick to let it continue to execute in the background: Use the PHP function ignore_user_abort(true) to tell PHP to continue the script execution after disconnection.
Let's say doing task like query through database with certain condition and delete matched data.
If there are too many data and not finish execution of the task within 30 seconds, what will happen?

Post Dynamic condition in Control M

We have multiple jobs that serves as threads for file loading. But we want to trigger jobs only when file is received. So we created a file watcher job in control-M. We want to trigger thread Job for each file. So one file will be processed by a single thread job.
For example: If only one file is received only one thread job should be triggered say Thread1 job is triggered. Now after 1 min a new file is received then since Thread1 job is already running so Thread 2 job should be initiated.
I think, if we could post condition pro-grammatically in Control-M my purpose will be solved.
Please help and comment if any more information is required.
You could have the filewatcher post a generic out-condition then configure a dummy job at the start of each thread that would require exclusive control over a control resource and on completion delete it's in-condition and kickoff the rest of the thread.
3 file arrive.
Filewatcher completes and posts out-condition.
Only one thread header can start, it then removes the out-condition and continues the thread.
Filewatcher runs again, completes and posts out-condition.
Only one thread header can start, it then removes the out-condition and continues the thread.
etc..
Its not clear where you are trying to use the conditions, but its possible to add conditions programatically using the ctmcontb utility.
ex: ctmcontb -ADD Condition_Name ODAT

Keep calling channel after called channel hangs up in Asterisk

I want to execute an AGI script for calling party after called party hangs up. For example, for doing a survey for customers I am going to run an AGI script after agent hangs up.
Unfortunately, when AGI scripts runs the agi debug output says:
"511: The command cannot be executed on a dead channel"
I use commands like "ANSWER" or "STREAM FILE" in my agi script which need a channel to run on.
I know that calling channel hangs up as soon as called party hangs up.
I tried DeadAGI instead of AGI and also "g" option in dial command but none of them works.
So, I think I have to search for a solution that keep the calling channel up so that I can run my script on that.
Any suggestion please?
You should not use "g" param for this case, because it is CALLER hangup. You should use "F"
F([[context^]exten^]priority): When the caller hangs up, transfer
the *called* party to the specified destination and *start* execution
at that location.
NOTE: Any channel variables you want the called channel to inherit
from the caller channel must be prefixed with one or two underbars ('_').
F: When the caller hangs up, transfer the *called* party to the next
priority of the current extension and *start* execution at that location.
NOTE: Any channel variables you want the called channel to inherit
from the caller channel must be prefixed with one or two underbars ('_').
NOTE: Using this option from a Macro() or GoSub() might not make
sense as there would be no return points.
g: Proceed with dialplan execution at the next priority in the current
extension if the destination channel hangs up.
Finally I found the answer. The problem is that we don't have to execute agi script in h extension otherwise we get an error for some functions like answer or streamfile in agi. we have to redirect the call to some extension before h extension and for that in elastix I had to change extensions.conf.

Asynchronous calls in OpenCPU

I would like to run OpenCPU job asynchronously and collect its results from a different session. In Rserve + RSclient I can do the following:
RS.eval(connection, expression, wait = FALSE)
# do something while the job is running
and then when I'm ready to receive results call either:
RS.collect(connection)
to try to collect results and wait until they are ready if job is still running or:
RS.collect(connection, timeout = 0)
if I want to check the job state and let it run if it is still not finished.
Is it possible with OpenCPU to receive the tmp/*/... path with the result id before the job has finished?
It seems acording to this post that OpenCPU does not support asynchronous jobs. Every request between the browser and the OpenCPU server must be alive in order to execute a script or function and receive a response succesfully.
If you find any workaround I would be pleased to know it.
In my case, I need to run a long process (may takes a few hours) and I can't keep alive the client request until the process finishes.

Resources