Improved error handling of streaming channels.
This commit is contained in:
parent
a95408fe90
commit
b0af4f85ee
2 changed files with 28 additions and 13 deletions
|
@ -159,17 +159,28 @@ stream all accounts
|
||||||
|
|
||||||
# start threads for each channel
|
# start threads for each channel
|
||||||
@@channel_stream[channel.id][:thread] = Thread.new {
|
@@channel_stream[channel.id][:thread] = Thread.new {
|
||||||
logger.debug "Started stream channel for '#{channel.id}' (#{channel.area})..."
|
begin
|
||||||
@@channel_stream[channel.id][:stream_instance] = channel.stream_instance
|
logger.debug "Started stream channel for '#{channel.id}' (#{channel.area})..."
|
||||||
@@channel_stream[channel.id][:stream_instance].stream
|
@@channel_stream[channel.id][:stream_instance] = channel.stream_instance
|
||||||
@@channel_stream[channel.id][:stream_instance].disconnect
|
@@channel_stream[channel.id][:stream_instance].stream
|
||||||
@@channel_stream[channel.id] = false
|
@@channel_stream[channel.id][:stream_instance].disconnect
|
||||||
logger.debug " ...stopped thread for '#{channel.id}'"
|
@@channel_stream[channel.id] = false
|
||||||
|
logger.debug " ...stopped thread for '#{channel.id}'"
|
||||||
|
rescue => e
|
||||||
|
error = "Can't use channel (#{channel.id}): #{e.inspect}"
|
||||||
|
logger.error error
|
||||||
|
logger.error e.backtrace
|
||||||
|
channel.status_in = 'error'
|
||||||
|
channel.last_log_in = error
|
||||||
|
channel.save
|
||||||
|
@@channel_stream[channel.id] = false
|
||||||
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# cleanup deleted channels
|
# cleanup deleted channels
|
||||||
last_channels.each {|channel_id|
|
last_channels.each {|channel_id|
|
||||||
|
next if !@@channel_stream[channel_id]
|
||||||
next if current_channels.include?(channel_id)
|
next if current_channels.include?(channel_id)
|
||||||
logger.debug "channel (#{channel_id}) not longer active, stop thread"
|
logger.debug "channel (#{channel_id}) not longer active, stop thread"
|
||||||
@@channel_stream[channel_id][:thread].exit
|
@@channel_stream[channel_id][:thread].exit
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TwitterBrowserTest < TestCase
|
||||||
end
|
end
|
||||||
twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
|
twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
|
||||||
|
|
||||||
hash = "#sweetcheck#{rand(99_999)}"
|
hash = "#sweetcheck#{rand(99_999)}"
|
||||||
|
|
||||||
@browser = browser_instance
|
@browser = browser_instance
|
||||||
login(
|
login(
|
||||||
|
@ -186,6 +186,9 @@ class TwitterBrowserTest < TestCase
|
||||||
css: '#content .main .action:nth-child(2)'
|
css: '#content .main .action:nth-child(2)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# wait till new streaming of channel is active
|
||||||
|
sleep 35
|
||||||
|
|
||||||
# start tweet from customer
|
# start tweet from customer
|
||||||
client = Twitter::REST::Client.new do |config|
|
client = Twitter::REST::Client.new do |config|
|
||||||
config.consumer_key = consumer_key
|
config.consumer_key = consumer_key
|
||||||
|
@ -194,7 +197,7 @@ class TwitterBrowserTest < TestCase
|
||||||
config.access_token_secret = twitter_customer_token_secret
|
config.access_token_secret = twitter_customer_token_secret
|
||||||
end
|
end
|
||||||
|
|
||||||
text = "Today... ##{hash} #{rand(99_999)}"
|
text = "Today... #{hash} #{rand(99_999)}"
|
||||||
tweet = client.update(
|
tweet = client.update(
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
|
@ -212,11 +215,12 @@ class TwitterBrowserTest < TestCase
|
||||||
|
|
||||||
watch_for(
|
watch_for(
|
||||||
css: '.content.active',
|
css: '.content.active',
|
||||||
value: "##{hash}",
|
value: "#{hash}",
|
||||||
|
timeout: 20,
|
||||||
)
|
)
|
||||||
|
|
||||||
ticket_open_by_title(
|
ticket_open_by_title(
|
||||||
title: "##{hash}",
|
title: "#{hash}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# reply via app
|
# reply via app
|
||||||
|
@ -246,19 +250,19 @@ class TwitterBrowserTest < TestCase
|
||||||
sleep 2
|
sleep 2
|
||||||
ticket_update(
|
ticket_update(
|
||||||
data: {
|
data: {
|
||||||
body: "@dzucker6 reply ##{hash}222 #{rand(99_999)}",
|
body: "@dzucker6 reply #{hash}222 #{rand(99_999)}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
sleep 20
|
sleep 20
|
||||||
|
|
||||||
match(
|
match(
|
||||||
css: '.content.active .ticket-article',
|
css: '.content.active .ticket-article',
|
||||||
value: "##{hash}222",
|
value: "#{hash}222",
|
||||||
)
|
)
|
||||||
|
|
||||||
# watch till tweet reached customer
|
# watch till tweet reached customer
|
||||||
text = nil
|
text = nil
|
||||||
client.search("##{hash}222", result_type: 'mixed').collect { |local_tweet|
|
client.search("#{hash}222", result_type: 'mixed').collect { |local_tweet|
|
||||||
text = local_tweet.text
|
text = local_tweet.text
|
||||||
}
|
}
|
||||||
assert(text)
|
assert(text)
|
||||||
|
|
Loading…
Reference in a new issue