5 Commits

Author SHA1 Message Date
Alexander Meindl
d04fcc814a Version bump to 1.0.10 2021-08-24 18:06:30 +02:00
Alexander Meindl
1730fb05fd Move asynchron delivery job to default Rails directory 2021-08-24 18:01:48 +02:00
Alexander Meindl
7326c81c5f Merge pull request #91 from Contargo/asynchronous-job
Use asynchronous ActiveJob for message delivery
2021-08-24 17:47:56 +02:00
Florian Krupicka
05d4b5bc8d Fix: missed a small param copied from the original network call 2021-08-24 17:13:55 +02:00
Florian Krupicka
f4fbf45895 Use asynchronous ActiveJob for message delivery
Calling out to a 3rd party web service like Slack or Mattermost blocks
the request for the current Redmine user. Depending on network latency,
this can result in very slow response on any action that is notified via
`redmine_messenger`.

Instead the backend call should make use of Rails builtin asynchronous
background job queuing (the same as used for Redmine mails), returning
to the user earlier.

We don't specify the actual queue backend for this job, so any Redmine
installation can select an appropiate queue backend by themselves or
simply use the default builtin backends.
2021-08-24 16:58:40 +02:00
4 changed files with 32 additions and 18 deletions

View File

@@ -1,6 +1,11 @@
Changelog
=========
1.0.10
-----
- Web service is called asynchron which does not block performance while sending message
1.0.9
-----

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
class MessengerDeliverJob < ActiveJob::Base
queue_as :default
def perform(url, params)
uri = URI url
http_options = { use_ssl: uri.scheme == 'https' }
http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless RedmineMessenger.setting? :messenger_verify_ssl
begin
req = Net::HTTP::Post.new uri
req.set_form_data payload: params.to_json
Net::HTTP.start uri.hostname, uri.port, http_options do |http|
response = http.request req
Rails.logger.warn response.inspect unless [Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPOK].include? response
end
rescue StandardError => e
Rails.logger.warn "cannot connect to #{url}"
Rails.logger.warn e
end
end
end

View File

@@ -1,8 +1,5 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
class Messenger
include Redmine::I18n
@@ -47,21 +44,8 @@ class Messenger
end
channels.each do |channel|
uri = URI url
params[:channel] = channel
http_options = { use_ssl: uri.scheme == 'https' }
http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless RedmineMessenger.setting? :messenger_verify_ssl
begin
req = Net::HTTP::Post.new uri
req.set_form_data payload: params.to_json
Net::HTTP.start uri.hostname, uri.port, http_options do |http|
response = http.request req
Rails.logger.warn response.inspect unless [Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPOK].include? response
end
rescue StandardError => e
Rails.logger.warn "cannot connect to #{url}"
Rails.logger.warn e
end
MessengerDeliverJob.perform_later url, params
end
end

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module RedmineMessenger
VERSION = '1.0.9'
VERSION = '1.0.10'
end