<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <tt>Ahmed,<br>
      <br>
      after an async() call, the execution never returns, but it
      continues exclusively via the resume route.<br>
      <br>
      Regards,<br>
    </tt>
    <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
    <div class="moz-cite-prefix">On 01/24/2017 05:06 PM, Ahmed Munir
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAGMN=JcOpB0NtjLvFpbXb3L7iR2o62BO3tfy7tntJjzkrhhY6g@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>I mean to say, after calling async statement, somehow it is
          not routing back the call to the main routing script after
          post DB query, see e.g. below for the current routing using
          async;<br>
          <br>
        </div>
        route [1]{<br>
        ....<br>
        <br>
        if($avp(Outpluseflag) == 0) {<br>
        async(avp_db_query("SELECT Outpulse_number,setid FROM
        Prefix_data where Program_prefix = '$avp(pg_prefix)'",
        "$avp(outpluse); $avp(trunkid)"),ob_route_1);<br>
        }<br>
        ..<br>
        }<br>
        <div><br>
        </div>
        <div>route[ob_route_1]{<br>
                  $avp(res)=$rc;<br>
          <br>
                  if ($avp(res) > 0) {<br>
                          cache_store("local", "DID_$tU",
          "$avp(outpluse)", 60);<br>
                          cache_store("local", "Trunk_$tU",
          "$avp(trunkid)", 60);<br>
          <br>
                  }<br>
          <br>
                  $avp(ru)=$(avp(ru){s.substr,1,0});<br>
          <br>
                  #Look for exten and trunk id for the FROM cache
          Internal number table<br>
                  if(cache_fetch("local", "$tU", $avp(iexten))) {<br>
                          if(cache_fetch("local", "GroupID_$tU",
          $avp(igroupid))) {<br>
                              #$var(flag) = 1;<br>
                              $avp(flag) = 1;<br>
                          }<br>
                  }<br>
          <br>
          <br>
          }<br>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">At first in route[1], I was setting up
          '$avp(ru)=$(avp(ru){s.substr,1,0});' and post routing script
          after async DB statement, but it is not resuming the route
          from there. As a work around, instead of setting up $avp(ru)
          and storing variable in cache in route[1], added them in
          route[ob_route_1] (as example above), it works.<br>
          <br>
        </div>
        <div class="gmail_extra">I would like to know, is there way
          after executing async DB statement (in route[ob_route_1]), we
          can resume back the route in route[1] or not?<br>
        </div>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Tue, Jan 24, 2017 at 9:09 AM,
            Bogdan-Andrei Iancu <span dir="ltr"><<a
                moz-do-not-send="true" href="mailto:bogdan@opensips.org"
                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:bogdan@opensips.org">bogdan@opensips.org</a></a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div bgcolor="#FFFFFF"> <tt>Could you please rephrase /
                  detail your question, as I do not understand what you
                  are asking.<br>
                  <br>
                  Thanks,<br>
                </tt><span class="gmail-">
                  <pre class="gmail-m_7817061351717095947moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a moz-do-not-send="true" class="gmail-m_7817061351717095947moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.<wbr>com</a></pre>
    </span><div><div class="gmail-h5"><div class="gmail-m_7817061351717095947moz-cite-prefix">On 01/24/2017 03:44 PM, Ahmed Munir
      wrote:

    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>Thanks, have been working on this and it is working.

          

        </div>
        Btw, I would like to know, is there a way to resume route while
        using async avp_db_query? As currently setting/declaring another
        async route for DB query, looking for resume route in main
        routing script.

        <div class="gmail_extra">

          <div class="gmail_quote">On Tue, Jan 24, 2017 at 6:45 AM,
            Bogdan-Andrei Iancu <span dir="ltr"><<a moz-do-not-send="true" class="gmail-m_7817061351717095947moz-txt-link-abbreviated" href="mailto:bogdan@opensips.org" target="_blank">bogdan@opensips.org</a>></span>
            wrote:

            <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
              <div bgcolor="#FFFFFF"> <tt>Hi Ahmed,

                  

                  Note the $rc holds the return code of the LAST
                  executed statement/instruction/function in the script.
                  In the first case you do it right by saving the ret
                  code of the avp_db_query into a separate variable, so
                  you can use it even later.

                  

                  In the sync script, the $rc, when entering the resume
                  route, it will hold the return code of the
                  avp_db_query() function. But the $rc will be changed
                  when doing the xlog(), the if(), etc...So when you do
                  the last xlog(), the $rc will have nothing to do with
                  the </tt><tt>avp_db_query(). If you need it later in
                  the script, better save it, as you do in the first
                  example.

                  

                  Regards,

                </tt>
                <pre class="gmail-m_7817061351717095947m_8980027315952255566moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a moz-do-not-send="true" class="gmail-m_7817061351717095947m_8980027315952255566moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.<wbr>com</a></pre><div><div class="gmail-m_7817061351717095947h5">
    <div class="gmail-m_7817061351717095947m_8980027315952255566moz-cite-prefix">On 01/20/2017 01:31 AM, Ahmed Munir
      wrote:

    </div>
    </div></div><blockquote type="cite"><div><div class="gmail-m_7817061351717095947h5">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>Hi,

                  

                </div>
                Currently I'm trying to use async fucntion for
                avp_db_query. The issue I'm facing while using it as not
                retrieving or returning correct return code and not
                execute later part of the routing script. See old &
                new DB queries;

                

              </div>
              Without Async:

              ----------------------

              route[1]{

              ...

              

               if($var(Outpluseflag) == 0) {

                            avp_db_query("SELECT Outpulse_number,setid
              FROM Prefix_data where Program_prefix =
              '$var(pg_prefix)'", "$avp(outpluse), $avp(trunkid)");

                              $var(res) = $retcode; # or you can just
              use $retcode!

                              xlog("--------- OB Route 1-1 DB fetched
              value outpluse -> $avp(outpluse) | trunkid ->
              $avp(trunkid) | Return Code: $rc | Var Res:
              $var(res)-------");

                              if ($var(res) > 0) {

                                         cache_store("local", "DID_$tU",
              "$avp(outpluse)", 60);

                                         cache_store("local",
              "Trunk_$tU", "$avp(trunkid)", 60);

                              }

                              #xlog("DB fetched value outpluse ->
              $avp(outpluse) | trunkid -> $avp(trunkid) | Return Code
              -> $var(res)");

                              xlog("--------- OB Route 1-2 DB fetched
              value outpluse -> $avp(outpluse) | trunkid ->
              $avp(trunkid) | Return Code: $rc | Var Res:
              $var(res)-------");

              }

            </div>
            }

            

            With Async:

            -------------------

          </div>
          route[1]{

          

        </div>
        <div>...

          

          <div>
            <div>
              <div>
                <div>if($var(Outpluseflag) == 0) {

                       async(avp_db_query("SELECT Outpulse_number,setid
                  FROM Prefix_data where Program_prefix =
                  '$var(pg_prefix)'", "$avp(outpluse),
                  $avp(trunkid)"),ob_route_1);

                  }

                  }

                  

                </div>
                <div>route[ob_route_1]{

                          xlog("--------- OB Route 1-1 DB fetched value
                  outpluse -> $avp(outpluse) | trunkid ->
                  $avp(trunkid) | Return Code: $rc-------");

                  

                          if ($rc > 0) {

                                 cache_store("local", "DID_$tU",
                  "$avp(outpluse)", 60);

                                 cache_store("local", "Trunk_$tU",
                  "$avp(trunkid)", 60);

                          }

                         xlog("--------- OB Route 1-2 DB fetched value
                  outpluse -> $avp(outpluse) | trunkid ->
                  $avp(trunkid) | Return Code: $rc-------");

                  

                  }

                </div>
                <div>
                  <div>

                    

                  </div>
                  <div>The records in xlog I'm getting without using
                    async;

                    

                    Jan 19 18:05:39 qorblpsisprxyd1
                    /usr/sbin/opensips[14040]: --------- OB Route 1-1 DB
                    fetched value outpluse -> <a moz-do-not-send="true" href="tel:%28609%29%20902-0000" value="+16099020000" target="_blank">6099020000</a> | trunkid
                    -> 117 | Return Code: 1 | Var Res: 1-------

                    Jan 19 18:05:39 qorblpsisprxyd1
                    /usr/sbin/opensips[14040]: --------- OB Route 1-2 DB
                    fetched value outpluse -> <a moz-do-not-send="true" href="tel:%28609%29%20902-0000" value="+16099020000" target="_blank">6099020000</a> | trunkid
                    -> 117 | Return Code: 1 | Var Res: 1-------

                    

                    <div>Whereas, records in xlog I'm getting using
                      async;

                      

                      Jan 19 18:10:07 qorblpsisprxyd1
                      /usr/sbin/opensips[14109]: --------- OB Route 1-1
                      DB fetched value outpluse -> <a moz-do-not-send="true" href="tel:%28609%29%20902-0000" value="+16099020000" target="_blank">6099020000</a> |
                      trunkid -> 117 | Return Code: 1-------

                      Jan 19 18:10:07 qorblpsisprxyd1
                      /usr/sbin/opensips[14109]: --------- OB Route 1-2
                      DB fetched value outpluse -> <a moz-do-not-send="true" href="tel:%28609%29%20902-0000" value="+16099020000" target="_blank">6099020000</a> |
                      trunkid -> 117 | Return Code: 0-------

                      

                    </div>
                    <div>Is there is way to properly retain the
                      $retcode/$rc in version 2.2.2? Seems like using
                      async return code(s) are not properly set or the
                      avp variables are not setting up correct using
                      async statement.

                      

                    </div>
                    <div>Please advise, if the above async db statement
                      is correct as shared in sample above.

                    </div>
                    

                    

                  </div>
                  <div>-- 

                    <div class="gmail-m_7817061351717095947m_8980027315952255566gmail_signature">Regards,

                      

                      Ahmed Munir Chohan

                      

                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      

      <fieldset class="gmail-m_7817061351717095947m_8980027315952255566mimeAttachmentHeader"></fieldset>
      

      </div></div><pre>______________________________<wbr>_________________
Users mailing list
<a moz-do-not-send="true" class="gmail-m_7817061351717095947m_8980027315952255566moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org" target="_blank">Users@lists.opensips.org</a>
<a moz-do-not-send="true" class="gmail-m_7817061351717095947m_8980027315952255566moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-<wbr>bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    

  </div>

</blockquote></div>


-- 
<div class="gmail-m_7817061351717095947gmail_signature">Regards,

Ahmed Munir Chohan

</div>
</div></div>



</blockquote>
</div></div></div></blockquote></div>


-- 
<div class="gmail_signature">Regards,

Ahmed Munir Chohan

</div>
</div></div>



</blockquote>
</body></html>