call.wait_for_joined with timeout

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

call.wait_for_joined with timeout

Andrius Kairiukstis-2
Hello,

I had to interrupt  call.wait_for_joined on timeout to send call to voicemail. 
Have tested various methods and stop on this one (ring_timeout), made from Timeont::timeout.

Please let me know is there any risks or possible issues or is there any way to do it better – call.wait_for_joined with timeout is core of my app and it must be very reliable!

  def ring_timeout
    loop_start_time = Time.now
    bl = proc do |exception|
      begin
        x = Thread.current
        y = Thread.start {
          begin
            loop do
              time_passed = Time.now - loop_start_time
              break if time_passed >= VoiceCore.config.ring_timeout && ! calls_joined?
              sleep 0.2
            end
            x.raise Timeout::Error
          rescue => e
            pp e
            x.raise e
          end
        }
        return yield
      ensure
        if y
          y.kill
          y.join # make sure y is dead.
        end
      end
    end
    bl.call
  end

  def wait_next_caller
    outgoing_call.update uuid: active_call_id,
      freeswitch_id: VoiceCore.config.freeswitch.id,
      user_callin_date: Sequel.function(:now)

    ringing = play! ringback_tone, repeat_times: (VoiceCore.config.ring_timeout / 4 + 1)

    call.on_joined do
      set_joined
      ringing.stop!
      answer
      play "beep.wav"
    end

    call.on_unjoined do
      outgoing_call.update user_hangup_date: Sequel.function(:now)
      hangup_call
    end

    begin
      ring_timeout {
        call.wait_for_joined active_call_id
      }
    rescue => e
      logger.debug "Timeout! #{e}"
    end

    unless calls_joined?
      logger.debug "Calling voicemail for #{callerid}"
      set_unjoined
      ringing.stop!
      invoke VoicemailRecord, metadata
    end
  end

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: call.wait_for_joined with timeout

Ben Langfeld-2

On 22 April 2015 at 05:42, Andrius Kairiukstis <[hidden email]> wrote:
Hello,

I had to interrupt  call.wait_for_joined on timeout to send call to voicemail. 
Have tested various methods and stop on this one (ring_timeout), made from Timeont::timeout.

Please let me know is there any risks or possible issues or is there any way to do it better – call.wait_for_joined with timeout is core of my app and it must be very reliable!

  def ring_timeout
    loop_start_time = Time.now
    bl = proc do |exception|
      begin
        x = Thread.current
        y = Thread.start {
          begin
            loop do
              time_passed = Time.now - loop_start_time
              break if time_passed >= VoiceCore.config.ring_timeout && ! calls_joined?
              sleep 0.2
            end
            x.raise Timeout::Error
          rescue => e
            pp e
            x.raise e
          end
        }
        return yield
      ensure
        if y
          y.kill
          y.join # make sure y is dead.
        end
      end
    end
    bl.call
  end

  def wait_next_caller
    outgoing_call.update uuid: active_call_id,
      freeswitch_id: VoiceCore.config.freeswitch.id,
      user_callin_date: Sequel.function(:now)

    ringing = play! ringback_tone, repeat_times: (VoiceCore.config.ring_timeout / 4 + 1)

    call.on_joined do
      set_joined
      ringing.stop!
      answer
      play "beep.wav"
    end

    call.on_unjoined do
      outgoing_call.update user_hangup_date: Sequel.function(:now)
      hangup_call
    end

    begin
      ring_timeout {
        call.wait_for_joined active_call_id
      }
    rescue => e
      logger.debug "Timeout! #{e}"
    end

    unless calls_joined?
      logger.debug "Calling voicemail for #{callerid}"
      set_unjoined
      ringing.stop!
      invoke VoicemailRecord, metadata
    end
  end

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.