Author Topic: Update a table on certain duration in cdr when a call finished  (Read 8327 times)

hamtrix

  • Newbie
  • *
  • Posts: 3
    • View Profile
Update a table on certain duration in cdr when a call finished
« on: November 07, 2016, 04:44:26 AM »
Hi,
I use this Script to check the digit length, compare the CALLED with my Blacklist, Compare it again with my Whitelist and route the call after thse filters, it works like a charm,
I need to update a table in mysql with the value of call duration once a call ends with like duration less than 65 seconds.
I have no idea how to that. I Install "call.cdr" with a priority right after Install call.route line, script fails and it keep reapiting the dialed number.

Any Idea ?


asymetrixs

  • Administrator
  • Newbie
  • *****
  • Posts: 47
    • View Profile
Re: Update a table on certain duration in cdr when a call finished
« Reply #1 on: February 05, 2017, 06:38:44 AM »
You receive 0-N call.cdr messages, because yate emits a new message every  time something in the call state has changed.
Therefore you should register a handler for call.cdr, but check the field 'operation' which is "initialize" (once), "update" (several times) or "finalize" (once the call has ended).
When receiving the operation=finalize message, you can do your tale updates.
see http://docs.yate.ro/wiki/CDR_Build_Module

Moreover, in case you use connection pooling, the cdr initialize/update/finalize messages do NOT come in order. There might be a finalize message appearing before an update message or even before the 'initialize' message. That is because yate queues the messages before sending them to the sql server but sends them in the best order regarding performance.
So in your SQL-Query you should make sure only to update the database records when you receive the 'finalize' message and if the call already has ended (record if ended=true in database and check on each initialize or update if it already ended) do not touch it anymore.
See http://docs.yate.ro/wiki/Register_Database_Schema bottom example implementation of a cdr initialize/update/finalize sql procedure.