async and event handlers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

async and event handlers

John Quick
I have a script which employs USRLOC to save registrations and also has an
event handler defined for E_UL_CONTACT_INSERT.
It is convenient, for the required logic/business rules, that I update a
user database from within the event handler.

If the DB update were happening directly from the main route, then I would
probably use async(avp_db_query())
However, if a potentially blocking operation - such as a DB write - is done
from within the event handler, am I correct in thinking that this is much
safer and therefore does not need to be wrapped in an async() or launch()
function call?

Can you even use async() or launch() from within an event handler?

Using v2.4.4

John Quick
Smartvox Limited



_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: async and event handlers

Ben Newlin
I think it would depend on whether you have defined the event handler itself to be sync or async. [1]

[1] https://opensips.org/html/docs/modules/2.4.x/event_route.html#overview

Ben Newlin

´╗┐On 3/20/19, 10:56 AM, "Users on behalf of John Quick" <[hidden email] on behalf of [hidden email]> wrote:

    I have a script which employs USRLOC to save registrations and also has an
    event handler defined for E_UL_CONTACT_INSERT.
    It is convenient, for the required logic/business rules, that I update a
    user database from within the event handler.
   
    If the DB update were happening directly from the main route, then I would
    probably use async(avp_db_query())
    However, if a potentially blocking operation - such as a DB write - is done
    from within the event handler, am I correct in thinking that this is much
    safer and therefore does not need to be wrapped in an async() or launch()
    function call?
   
    Can you even use async() or launch() from within an event handler?
   
    Using v2.4.4
   
    John Quick
    Smartvox Limited
   
   
   
    _______________________________________________
    Users mailing list
    [hidden email]
    http://lists.opensips.org/cgi-bin/mailman/listinfo/users
   
   

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: async and event handlers

John Quick
In reply to this post by John Quick
Ben,

Thanks. I hadn't spotted that little detail in the Event Handler
documentation.

My event handler first retrieves some data about the relevant AOR from the
DB, then updates it, then writes it back.
Interestingly, when I add "async" as a 2nd parameter in the event handler
definition, this breaks the initial DB lookup.
The error message reported is:
ERROR: core: cachedb_fetch: failed to get connection for grp name [userdb] :
check db_url

It would appear that the cachedb information from the modparam section of my
script is not available to an asynchronous event handler, but is to a
synchronous one.

John Quick
Smartvox Limited



_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: async and event handlers

Bogdan-Andrei Iancu-2
In reply to this post by John Quick
Hi John,

I don't think you can "replicate" the event triggers with some
avp_db_query() from script. When you so a save(location), you never know
if that call will translate into updating an existing contact or in
inserting a new one - this is no visible at script level

Regards,

Bogdan-Andrei Iancu

OpenSIPS Founder and Developer
   https://www.opensips-solutions.com
OpenSIPS Summit 2019
   https://www.opensips.org/events/Summit-2019Amsterdam/

On 03/20/2019 04:55 PM, John Quick wrote:

> I have a script which employs USRLOC to save registrations and also has an
> event handler defined for E_UL_CONTACT_INSERT.
> It is convenient, for the required logic/business rules, that I update a
> user database from within the event handler.
>
> If the DB update were happening directly from the main route, then I would
> probably use async(avp_db_query())
> However, if a potentially blocking operation - such as a DB write - is done
> from within the event handler, am I correct in thinking that this is much
> safer and therefore does not need to be wrapped in an async() or launch()
> function call?
>
> Can you even use async() or launch() from within an event handler?
>
> Using v2.4.4
>
> John Quick
> Smartvox Limited
>
>
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users