qless-growl 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/qless-growl +99 -0
  2. metadata +96 -0
@@ -0,0 +1,99 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'qless'
6
+ require 'ruby-growl'
7
+ require 'micro-optparse'
8
+
9
+ @options = Parser.new do |p|
10
+ p.banner = 'This agent lets you get campfire notifications for the progress of tracked jobs'
11
+ p.option :growl , 'host for the growl daemon', :default => 'localhost'
12
+ p.option :app , 'application name for notifications', :default => 'qless'
13
+ p.option :host , 'host:port for your qless redis instance', :default => 'localhost:6379'
14
+ p.option :web , 'host:port for your qless web ui', :default => 'localhost:5678'
15
+ end.process!
16
+
17
+ # Connect to growl
18
+ puts 'Connecting to growl...'
19
+ @growl = Growl::GNTP.new @options[:growl], @options[:app]
20
+
21
+ # Qless client
22
+ puts 'Connecting to qless...'
23
+ @client = Qless::Client.new(:host => @options[:host])
24
+
25
+ %w{canceled completed failed popped stalled put track untrack}.each do |t|
26
+ @growl.add_notification(t)
27
+ end
28
+ @growl.register
29
+
30
+ def notify(jid, event, &block)
31
+ job = @client.jobs[jid]
32
+ if job.nil?
33
+ message = yield job
34
+ puts "#{jid} -> Notifying #{message}"
35
+ @growl.notify(event, "#{jid[0...8]}", "#{message}", 0, false, jid, "http://#{@options[:web]}/jobs/#{jid}")
36
+ else
37
+ message = yield job
38
+ puts "#{jid} -> Notifying #{message}"
39
+ @growl.notify(event, "#{jid[0...8]} [#{job.tags.join(', ')}]", "#{message}", 0, false, jid, "http://#{@options[:web]}/jobs/#{jid}")
40
+ end
41
+ end
42
+
43
+ @client.events.listen do |on|
44
+ on.canceled { |jid| notify(jid, 'canceled') { |job| 'canceled' } }
45
+ on.stalled { |jid| notify(jid, 'canceled') { |job| 'stalled' } }
46
+ on.track { |jid| notify(jid, 'canceled') { |job| 'is being tracked' } }
47
+ on.untrack { |jid| notify(jid, 'canceled') { |job| 'no longer tracked' } }
48
+
49
+ on.completed do |jid|
50
+ notify(jid, 'completed') do |job|
51
+ if job
52
+ if job.queue_name.empty?
53
+ "completed"
54
+ else
55
+ "advanced to #{job.queue_name}"
56
+ end
57
+ else
58
+ "completed"
59
+ end
60
+ end
61
+ end
62
+
63
+ on.failed do |jid|
64
+ notify(jid, 'failed') do |job|
65
+ if job
66
+ "failed by #{job.failure['worker']}"
67
+ else
68
+ "failed"
69
+ end
70
+ end
71
+ end
72
+
73
+ on.popped do |jid|
74
+ notify(jid, 'popped') do |job|
75
+ if job
76
+ "popped by #{job.worker_name}"
77
+ else
78
+ "popped"
79
+ end
80
+ end
81
+ end
82
+
83
+ on.put do |jid|
84
+ notify(jid, 'put') do |job|
85
+ if job
86
+ "moved to #{job.queue_name}"
87
+ else
88
+ "moved"
89
+ end
90
+ end
91
+ end
92
+
93
+ puts 'Listening...'
94
+
95
+ Signal.trap("INT") do
96
+ puts 'Exiting'
97
+ Process.exit(0)
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qless-growl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Lecocq
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qless
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ruby-growl
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '4.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '4.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: micro-optparse
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ description: ! "\n Get Growl notifications for jobs you're tracking in your qless\n
63
+ \ queue.\n "
64
+ email:
65
+ - dan@seomoz.org
66
+ executables:
67
+ - qless-growl
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - bin/qless-growl
72
+ homepage: http://github.com/seomoz/qless
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project: qless-growl
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Growl Notifications for Qless
96
+ test_files: []