notifyor 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d502004be90a818b8dc72451657eed6345835b4d
4
- data.tar.gz: aba81061f68c9a5d400ea64171eb5f4e4cf21008
3
+ metadata.gz: 5a06c37ee1d957d65e8d85fc3f2a7fe548a17fc8
4
+ data.tar.gz: a23b2405dc4b7a2ff8f498aa567aa8f749c5d34a
5
5
  SHA512:
6
- metadata.gz: 32c5233533ea70d62ddc3b10a5718f04f1a98e6f4f8385a534a3ca40df9376a53639eeda7992bb79b3ff530459c832c651276abba1e8b94794155fd1ed7f0e72
7
- data.tar.gz: 7c9a06aa49e1c29d2eccf7a063c5c5073c1829100fe4e81b42f9faa0f4cf82912292ac4dfb38552901da72ed14468a1e45360c6c4996bd2978ee324a098b6d3e
6
+ metadata.gz: 281d8842cc4fbefca6577f019b095f9e6bf2f72990bf9d1e62de88e4069e645417b4852f09c88394543fb2227f138f288cee27a44598c69903453c907d0844ac
7
+ data.tar.gz: 0d11f8684dc3b83c4237eb79fb31c1fef8c5bece12b7ea3515088ed259f006f2755a59abbf57884b538a5afcf3fe274869ab1b076b68a4e4f70efb916d8d6d88
data/lib/notifyor/cli.rb CHANGED
@@ -23,10 +23,6 @@ module Notifyor
23
23
  ::Notifyor.configuration.ssh_host = host
24
24
  end
25
25
 
26
- opts.on('--ssh-password password', 'Provide the ssh password for the deployment/remote server') do |password|
27
- ::Notifyor.configuration.ssh_password = password
28
- end
29
-
30
26
  opts.on('--ssh-port port', 'Provide the ssh port for the deployment/remote server') do |port|
31
27
  ::Notifyor.configuration.ssh_port = port
32
28
  end
@@ -34,16 +30,25 @@ module Notifyor
34
30
  opts.on('--ssh-user user', 'Provide the ssh user for the deployment/remote server') do |user|
35
31
  ::Notifyor.configuration.ssh_user = user
36
32
  end
33
+
34
+ opts.on('--tunnel-port tunnel_port', 'Provide the ssh user for the deployment/remote server') do |tunnel_port|
35
+ ::Notifyor.configuration.tunnel_port = tunnel_port
36
+ end
37
+
38
+ opts.on('--redis-port redis_port', 'Provide the ssh user for the deployment/remote server') do |redis_port|
39
+ ::Notifyor.configuration.redis_port = redis_port
40
+ end
37
41
  end.parse!
38
42
  end
39
43
 
40
44
  def check_notifications
41
- loop do
42
- ::Notifyor.configuration.notifyor_models.each do |model|
43
- connection = Notifyor::Remote::Connection.new
44
- connection.growl_message(model.tableize)
45
- end
46
- sleep 5
45
+ connection = Notifyor::Remote::Connection.new
46
+ begin
47
+ connection.build_tunnel
48
+ connection.build_redis_tunnel_connection
49
+ connection.subscribe_to_redis
50
+ rescue => e
51
+ STDOUT.write "Could not establish SSH tunnel. Reason: #{e.message}"
47
52
  end
48
53
  end
49
54
 
@@ -1,20 +1,20 @@
1
- require 'redis-objects'
1
+ require 'redis'
2
2
  require 'connection_pool'
3
3
  module Notifyor
4
4
  class Configuration
5
5
  attr_accessor :redis_connection
6
- attr_accessor :notifyor_models
7
6
  attr_accessor :ssh_host
8
7
  attr_accessor :ssh_user
9
- attr_accessor :ssh_password
10
8
  attr_accessor :ssh_port
9
+ attr_accessor :tunnel_port
10
+ attr_accessor :redis_port
11
11
 
12
12
  def initialize
13
13
  @redis_connection = ::Redis.new
14
- Redis::Objects.redis = ::ConnectionPool.new(size: 5, timeout: 5) { @redis_connection }
15
- @notifyor_models = Set.new
16
- @ssh_port = 22
14
+ @ssh_port = '22'
17
15
  @ssh_host = 'localhost'
16
+ @tunnel_port ='2000'
17
+ @redis_port = '6379'
18
18
  end
19
19
  end
20
20
  end
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'redis'
2
3
 
3
4
  module Notifyor
4
5
  module Plugin
@@ -8,14 +9,8 @@ module Notifyor
8
9
  end
9
10
 
10
11
  module ClassMethods
11
- attr_accessor :notifyor_events
12
- attr_accessor :notifyor_models
13
-
14
12
  def notifyor(options = {})
15
13
  configure_plugin(options)
16
- self.extend ::Redis::Objects
17
- ::Notifyor.configuration.notifyor_models.add(self.name)
18
- self.notifyor_events = ::Redis::List.new("notifyor:#{self.name.tableize}")
19
14
  end
20
15
 
21
16
  def configure_plugin(options = {})
@@ -27,11 +22,11 @@ module Notifyor
27
22
  configuration[:only].each do |action|
28
23
  case action
29
24
  when :create
30
- self.after_commit -> { self.class.notifyor_events << configuration[:messages][:create].call(self) }, on: :create, if: -> { configuration[:only].include? :create}
25
+ self.after_commit -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:create].call(self)}.to_json }, on: :create, if: -> { configuration[:only].include? :create }
31
26
  when :update
32
- self.after_commit -> {self.class.notifyor_events << configuration[:messages][:update].call(self) }, on: :update, if: -> { configuration[:only].include? :update}
27
+ self.after_commit -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:update].call(self)}.to_json }, on: :update, if: -> { configuration[:only].include? :update }
33
28
  when :destroy
34
- self.before_destroy -> {self.class.notifyor_events << configuration[:messages][:destroy].call(self)}, if: -> { configuration[:only].include? :destroy}
29
+ self.before_destroy -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:destroy].call(self)}.to_json }, if: -> { configuration[:only].include? :destroy }
35
30
  else
36
31
  #nop
37
32
  end
@@ -3,40 +3,44 @@ require 'notifyor'
3
3
  require 'notifyor/growl'
4
4
  require 'notifyor/util/formatter'
5
5
  require 'notifyor/errors/ssh_error'
6
+ require 'net/ssh/gateway'
6
7
  module Notifyor
7
8
  module Remote
8
9
  class Connection
9
10
 
10
11
  def initialize
11
12
  @ssh_host = ::Notifyor.configuration.ssh_host
12
- @ssh_password = ::Notifyor.configuration.ssh_password
13
13
  @ssh_port = ::Notifyor.configuration.ssh_port
14
14
  @ssh_user = ::Notifyor.configuration.ssh_user
15
+ @tunnel_port = ::Notifyor.configuration.tunnel_port
16
+ @redis_port = ::Notifyor.configuration.redis_port
17
+ @ssh_gateway = nil
18
+ @redis_tunnel_connection = nil
15
19
  end
16
20
 
17
- def build_ssh_cmd
18
- if @ssh_host.blank?
19
- raise ::Notifyor::Errors::SSHError, "no ssh host provided. Provide a host with the --ssh-host option or set it in your configuration."
21
+ def build_tunnel
22
+ unless ['127.0.0.1', 'localhost'].include? @ssh_host
23
+ @ssh_gateway = Net::SSH::Gateway.new(@ssh_host, @ssh_user, port: @ssh_port)
24
+ @ssh_gateway.open('127.0.0.1', @redis_port, @tunnel_port)
20
25
  end
21
- ssh_cmd = @ssh_user.present? ? "ssh #{@ssh_user}:#{@ssh_password}@#{@ssh_host}" : "ssh #{@ssh_host}"
22
- ssh_cmd + " -p#{@ssh_port ? @ssh_port : 22}"
23
26
  end
24
27
 
25
- def build_redis_cmd(model_name)
26
- "redis-cli LPOP notifyor:#{model_name}"
28
+ def build_redis_tunnel_connection
29
+ redis_port = (['127.0.0.1', 'localhost'].include? @ssh_host) ? @redis_port : @tunnel_port
30
+ @redis_tunnel_connection = Redis.new(port: redis_port)
27
31
  end
28
32
 
29
- def retrieve_value(model_name)
30
- if ['127.0.0.1', 'localhost'].include? @ssh_host
31
- %x(#{build_redis_cmd(model_name)})
32
- else
33
- %x(#{build_ssh_cmd} '#{build_redis_cmd(model_name)}')
33
+ def subscribe_to_redis
34
+ @redis_tunnel_connection.subscribe('notifyor') do |on|
35
+ on.message do |channel, msg|
36
+ data = JSON.parse(msg)
37
+ growl_message(data['message'])
38
+ end
34
39
  end
35
40
  end
36
41
 
37
- def growl_message(model_name)
38
- value = retrieve_value(model_name)
39
- ::Notifyor::Growl.create_growl("Notifyor", value) unless Notifyor::Util::Formatter.squish!(value).empty?
42
+ def growl_message(message)
43
+ ::Notifyor::Growl.create_growl("Notifyor", message) unless Notifyor::Util::Formatter.squish!(message).empty?
40
44
  end
41
45
  end
42
46
  end
@@ -1,3 +1,3 @@
1
1
  module Notifyor
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
Binary file
@@ -193,3 +193,9 @@ Migrating to CreateUsers (20160404044940)
193
193
   (0.3ms) begin transaction
194
194
  SQL (1.6ms) UPDATE "users" SET "first_name" = ?, "updated_at" = ? WHERE "users"."id" = ? [["first_name", "erwin"], ["updated_at", "2016-04-05 19:15:08.874646"], ["id", 5]]
195
195
   (2.3ms) commit transaction
196
+  (0.3ms) begin transaction
197
+ SQL (1.9ms) INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-06 08:51:10.426367"], ["updated_at", "2016-04-06 08:51:10.426367"]]
198
+  (6.1ms) commit transaction
199
+  (0.1ms) begin transaction
200
+ SQL (1.1ms) INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-06 08:54:59.353124"], ["updated_at", "2016-04-06 08:54:59.353124"]]
201
+  (39.3ms) commit transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-ssh
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: net-ssh-gateway
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: sqlite3
71
99
  requirement: !ruby/object:Gem::Requirement