kthxbye 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -8,15 +8,14 @@ source "http://rubygems.org"
8
8
  group :development do
9
9
  gem "shoulda", ">= 0"
10
10
  gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.0.pre3"
12
11
  gem "rcov", ">= 0"
13
12
  end
14
13
 
15
14
  gem "redis"
15
+
16
16
  begin
17
17
  gem "yajl-ruby"
18
18
  rescue
19
19
  gem "json"
20
20
  end
21
21
 
22
- gem 'sinatra'
data/README.textile CHANGED
@@ -76,6 +76,64 @@ and then in some other world, on some other machine, (that still has knowledge o
76
76
 
77
77
  Pretty... damn... simple.
78
78
 
79
+ h2. Installation
80
+ Installation isn't hard. Simply:
81
+
82
+ gem install kthxbye
83
+
84
+ or in Rails
85
+
86
+ gem "kthxbye"
87
+
88
+ and then in your project directory run
89
+
90
+ rails g kthxbye
91
+
92
+ which will install all of the necessary assets, of which there are three:
93
+ # public/javascripts/kthxbye.js - a responder that will catch job status message
94
+ from the worker
95
+ # public/images/kthxbye_widget.png - a notifier widget to show the status of a
96
+ job
97
+ # public/stylesheets/kthxbye.css - styles for the widget
98
+
99
+ These can be ignored if you really don't want to have an asynchronus widget to
100
+ display the job's status to the user in real-time. You can simply use the gem
101
+ and get the results on your own time.
102
+
103
+ If are using the widget however, we depend on "node.js":http://nodejs.org/ to
104
+ handle the Redis PUBSUB listening and updating and "Socket.io":http://socket.io/
105
+ to stream the results back to the clients.
106
+
107
+ In order to install Socket.io on your application side, run
108
+ git clone http://github.com/LearnBoost/Socket.IO.git socket-io --recursive
109
+
110
+ *Note:* due to the way Rails tries to serve these files and the seemingly
111
+ conflicting way that Socket.io has hardcoded some paths into the code, you may
112
+ need to create a symlink to the public/javascripts/socket.io directory in you
113
+ public directory. This was the easiest solution I found.
114
+
115
+ There is a separate node.js client at "github.com/plukevdh/kthxbye-node":http://github.com/plukevdh/kthxbye-node
116
+ Simply clone the repo or download the poll.js file and set it up to your hearts
117
+ content. *NOTE:* You will need to configure your ports/redis server in the
118
+ poll.js file as well as installing socket.io in the same dir as the poll.js file
119
+ via "git clone git://github.com/LearnBoost/Socket.IO-node.git socket.io-node --recursive"
120
+ (from the socket.io install instructions http://github.com/LearnBoost/Socket.IO-node)
121
+
122
+
123
+ h2. Troubleshooting
124
+ h3. The part of the show where I try to save you some trouble
125
+
126
+ There are a few things I found along the way that were necessary to make this
127
+ integration run super smoothly:
128
+
129
+ You will need to run node as root user if you want to take advantage of
130
+ flashsockets.
131
+
132
+ You may need to create a link in your public/ dir to socket.io to the install
133
+ in your public/javascripts/ dir.
134
+
135
+
136
+
79
137
  h2. Note on Patches/Pull Requests
80
138
 
81
139
  * Fork the project.
@@ -0,0 +1,11 @@
1
+ Description:
2
+ The 'kthxbye' command installs the necessary resource files to your Rails
3
+ application so that you can use the notification widget and modify any
4
+ job completion actions for the front-end
5
+
6
+ Example:
7
+ rails g kthxbye:all
8
+
9
+ This installs all the resource files (images, javascripts, css files) into
10
+ the proper locations in your public/ dir.
11
+
@@ -0,0 +1,51 @@
1
+ require 'rails/generators'
2
+
3
+ module Kthxbye
4
+ module Generators
5
+ class KthxbyeGenerator < Rails::Generators::Base
6
+
7
+ desc "installs all necessary Kthxbye files for notification widget"
8
+
9
+ class_option :js, :type => :boolean, :default => true, :desc => "install javascript files"
10
+ class_option :img, :type => :boolean, :default => true, :desc => "install widget image"
11
+ class_option :css, :type => :boolean, :default => true, :desc => "install css files"
12
+
13
+ def self.source_root
14
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
15
+ end
16
+
17
+ def self.banner
18
+ "#{$0} kthxbye #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
19
+ end
20
+
21
+ def install_all
22
+ install_javascripts
23
+ install_css
24
+ install_images
25
+ install_gems
26
+
27
+ puts "Successfully installed Kthxbye resources in public/"
28
+ end
29
+
30
+ private
31
+
32
+ def install_javascripts
33
+ copy_file("kthxbye.js", "public/javascripts/kthxbye.js") if options[:js]
34
+ end
35
+
36
+ def install_css
37
+ copy_file("kthxbye.css", "public/stylesheets/kthxbye.css") if options[:css]
38
+ end
39
+
40
+ def install_images
41
+ copy_file("kthxbye_widget.png", "public/images/kthxbye_widget.png") if options[:img]
42
+ end
43
+
44
+ def install_gems
45
+ gem("redis", "~> 2.0.10")
46
+ gem("yajl-ruby", "~> 0.7.8")
47
+ gem("kthxbye", "~> #{Kthxbye::Version}")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ #kthxbye {
2
+ height: 41px;
3
+ width: 124px;
4
+ background:url('../images/kthxbye_widget.png') no-repeat;
5
+ margin:10px;
6
+ }
7
+
8
+ #kthxbye.failed {
9
+ background-position: 0 -120px;
10
+ }
11
+
12
+ #kthxbye.success {
13
+ background-position: 0 -40px;
14
+ }
15
+
16
+ #kthxbye.active {
17
+ background-position: 0 -80px;
18
+ }
@@ -0,0 +1,41 @@
1
+ io.setPath("/javascripts/socket.io/")
2
+ var socket = new io.Socket('localhost', {port:8081})
3
+
4
+ function active() {
5
+ $('#kthxbye').removeClass("failed success").addClass("active")
6
+ }
7
+
8
+ function failed() {
9
+ $('#kthxbye').removeClass("active success").addClass("failed")
10
+ }
11
+
12
+ function succeeded() {
13
+ $('#kthxbye').removeClass("active failed").addClass("success")
14
+ }
15
+
16
+
17
+
18
+ if(socket.connect()) {
19
+ socket.on('message', function(data) {
20
+ try {
21
+ var status = JSON.parse(data)
22
+ } catch (SyntaxError) {
23
+ return false;
24
+ }
25
+
26
+ if(status.id != parseInt(job_id)) return false;
27
+
28
+ if(status.status == 'job.failed') {
29
+ failed()
30
+ } else if(status.status == 'job.completed') {
31
+ succeeded()
32
+ } else if(status.status == 'job.started') {
33
+ active()
34
+ } else {
35
+ alert('Unknown option! ' + status.status)
36
+ }
37
+
38
+ return false
39
+ })
40
+ }
41
+
data/lib/kthxbye.rb CHANGED
@@ -6,8 +6,6 @@ rescue
6
6
  require 'json'
7
7
  end
8
8
 
9
- $LOAD_PATH << './lib'
10
-
11
9
  require 'kthxbye/config'
12
10
  require 'kthxbye/helper'
13
11
  require 'kthxbye/job'
@@ -18,6 +16,8 @@ require 'kthxbye/version'
18
16
 
19
17
  require 'kthxbye/exceptions'
20
18
 
19
+ require 'kthxbye/railtie' if defined?(Rails) && Rails::VERSION::MAJOR == 3
20
+
21
21
  # Kthxbye is a light-weight, distributed delayed-job processor. It is meant
22
22
  # to take the load of long running processes off of your web-server any place
23
23
  # it in the capable hands of a backend processor. It is unique in that it
data/lib/kthxbye/job.rb CHANGED
@@ -111,6 +111,8 @@ module Kthxbye
111
111
  # It will get the jobs class, payload and then run the job, storing the
112
112
  # result in the result's store once complete. Also responsible for reporting
113
113
  # errors and storing the job in the failure listing if an exception occurs.
114
+ # Will also publish a message on the job.failed channel (Redis PUBSUB) with
115
+ # the id of the failed job
114
116
  def perform
115
117
  begin
116
118
  @klass = Object.const_get(@data['klass'])
@@ -124,6 +126,7 @@ module Kthxbye
124
126
  rescue Object => ex
125
127
  @failed_attempts += 1
126
128
  log "Error occured: #{ex.message}. Try: #{@failed_attempts}/#{Kthxbye::Config.options[:attempts]}"
129
+ redis.publish("job.failed", @id)
127
130
  return Kthxbye::Failure.create( self, ex ) if @failed_attempts >= Kthxbye::Config.options[:attempts]
128
131
  perform
129
132
  end
@@ -0,0 +1,18 @@
1
+ # Rake tasks and integration to Rails
2
+ # require 'kthxbye'
3
+
4
+ module Kthxbye
5
+ class Railtie < Rails::Railtie
6
+
7
+ config.action_view.javascript_expansions[:kthxbye] = %w(socket.io/socket.io.js kthxbye.js)
8
+
9
+ initializer "kthxbye.configure_for_rails" do |app|
10
+ app.config.autoload_paths += %W(kthxbye/css kthxbye/javascripts kthxbye/images)
11
+ end
12
+
13
+ rake_tasks do
14
+ load "kthxbye/railties/kthxbye.rake"
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ namespace :kthxbye do
2
+ end
3
+
@@ -1,5 +1,5 @@
1
1
  module Kthxbye
2
2
  # Returns current version of Kthxbye
3
- Version = VERSION = File.read(File.dirname(__FILE__)+'/../../VERSION').chomp
3
+ Version = VERSION = "1.1.0"
4
4
  end
5
5
 
@@ -133,6 +133,7 @@ module Kthxbye
133
133
 
134
134
  # activates job
135
135
  job.active
136
+ redis.publish("job.started", job.id)
136
137
  end
137
138
 
138
139
  # Is this job working?
@@ -145,6 +146,7 @@ module Kthxbye
145
146
  redis.srem( :working, self )
146
147
  redis.del( "worker:#{self}" )
147
148
  log "Completed job #{@current_job}"
149
+ redis.publish("job.completed", @current_job.id)
148
150
  @current_job = nil
149
151
  end
150
152
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kthxbye
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
7
+ - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ version: 1.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Luke van der Hoeven
@@ -15,112 +14,10 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-24 00:00:00 -04:00
17
+ date: 2010-10-05 00:00:00 -04:00
19
18
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- name: redis
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- requirement: *id001
34
- type: :runtime
35
- - !ruby/object:Gem::Dependency
36
- prerelease: false
37
- name: yajl-ruby
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
47
- requirement: *id002
48
- type: :runtime
49
- - !ruby/object:Gem::Dependency
50
- prerelease: false
51
- name: sinatra
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- requirement: *id003
62
- type: :runtime
63
- - !ruby/object:Gem::Dependency
64
- prerelease: false
65
- name: shoulda
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- requirement: *id004
76
- type: :development
77
- - !ruby/object:Gem::Dependency
78
- prerelease: false
79
- name: bundler
80
- version_requirements: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- hash: 23
86
- segments:
87
- - 1
88
- - 0
89
- - 0
90
- version: 1.0.0
91
- requirement: *id005
92
- type: :development
93
- - !ruby/object:Gem::Dependency
94
- prerelease: false
95
- name: jeweler
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- hash: 270495430
102
- segments:
103
- - 1
104
- - 5
105
- - 0
106
- - pre3
107
- version: 1.5.0.pre3
108
- requirement: *id006
109
- type: :development
110
- - !ruby/object:Gem::Dependency
111
- prerelease: false
112
- name: rcov
113
- version_requirements: &id007 !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 3
119
- segments:
120
- - 0
121
- version: "0"
122
- requirement: *id007
123
- type: :development
19
+ dependencies: []
20
+
124
21
  description: "Kthxbye is the answer to a fairly unique-yet-common problem: Background job processing when we care about the result."
125
22
  email: hungerandthirst@gmail.com
126
23
  executables: []
@@ -131,46 +28,48 @@ extra_rdoc_files:
131
28
  - LICENSE
132
29
  - README.textile
133
30
  files:
134
- - .document
135
- - .gitignore
136
- - DESIGN.textile
137
- - Gemfile
138
- - Gemfile.lock
139
- - LICENSE
140
- - README.textile
141
- - Rakefile
142
- - VERSION
143
- - config.ru
144
- - lib/kthxbye.rb
145
- - lib/kthxbye/config.rb
146
- - lib/kthxbye/exceptions.rb
147
- - lib/kthxbye/failure.rb
148
- - lib/kthxbye/helper.rb
149
- - lib/kthxbye/job.rb
150
31
  - lib/kthxbye/version.rb
32
+ - lib/kthxbye/job.rb
33
+ - lib/kthxbye/exceptions.rb
151
34
  - lib/kthxbye/web_interface.rb
35
+ - lib/kthxbye/web_interface/public/jquery.js
152
36
  - lib/kthxbye/web_interface/public/application.js
153
37
  - lib/kthxbye/web_interface/public/awesome-buttons.css
154
- - lib/kthxbye/web_interface/public/jquery.js
155
38
  - lib/kthxbye/web_interface/public/style.css
156
- - lib/kthxbye/web_interface/views/error.haml
157
- - lib/kthxbye/web_interface/views/failed.haml
39
+ - lib/kthxbye/web_interface/views/workers.haml
158
40
  - lib/kthxbye/web_interface/views/hash.haml
159
- - lib/kthxbye/web_interface/views/layout.haml
160
41
  - lib/kthxbye/web_interface/views/overview.haml
161
- - lib/kthxbye/web_interface/views/queues.haml
42
+ - lib/kthxbye/web_interface/views/failed.haml
162
43
  - lib/kthxbye/web_interface/views/set.haml
163
- - lib/kthxbye/web_interface/views/stats.haml
164
44
  - lib/kthxbye/web_interface/views/view_backtrace.haml
165
- - lib/kthxbye/web_interface/views/workers.haml
45
+ - lib/kthxbye/web_interface/views/layout.haml
46
+ - lib/kthxbye/web_interface/views/queues.haml
47
+ - lib/kthxbye/web_interface/views/error.haml
48
+ - lib/kthxbye/web_interface/views/stats.haml
166
49
  - lib/kthxbye/web_interface/views/working.haml
50
+ - lib/kthxbye/failure.rb
51
+ - lib/kthxbye/config.rb
52
+ - lib/kthxbye/railtie.rb
53
+ - lib/kthxbye/helper.rb
167
54
  - lib/kthxbye/worker.rb
168
- - test/helper.rb
55
+ - lib/kthxbye/railties/kthxbye.rake
56
+ - lib/generators/kthxbye/templates/kthxbye.css
57
+ - lib/generators/kthxbye/templates/kthxbye_widget.png
58
+ - lib/generators/kthxbye/templates/kthxbye.js
59
+ - lib/generators/kthxbye/USAGE
60
+ - lib/generators/kthxbye/kthxbye_generator.rb
61
+ - lib/kthxbye.rb
62
+ - LICENSE
63
+ - README.textile
64
+ - DESIGN.textile
65
+ - config.ru
66
+ - Gemfile
67
+ - test/test_kthxbye.rb
169
68
  - test/redis-test.conf
170
- - test/test_failure.rb
171
69
  - test/test_helper.rb
172
- - test/test_kthxbye.rb
70
+ - test/test_failure.rb
173
71
  - test/test_worker.rb
72
+ - test/helper.rb
174
73
  has_rdoc: true
175
74
  homepage: http://github.com/plukevdh/kthxbye
176
75
  licenses: []
@@ -185,7 +84,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
84
  requirements:
186
85
  - - ">="
187
86
  - !ruby/object:Gem::Version
188
- hash: 3
189
87
  segments:
190
88
  - 0
191
89
  version: "0"
@@ -194,10 +92,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
92
  requirements:
195
93
  - - ">="
196
94
  - !ruby/object:Gem::Version
197
- hash: 3
198
95
  segments:
199
- - 0
200
- version: "0"
96
+ - 1
97
+ - 3
98
+ - 6
99
+ version: 1.3.6
201
100
  requirements: []
202
101
 
203
102
  rubyforge_project:
@@ -206,8 +105,9 @@ signing_key:
206
105
  specification_version: 3
207
106
  summary: Async processing + results notification
208
107
  test_files:
209
- - test/helper.rb
210
- - test/test_failure.rb
211
- - test/test_helper.rb
212
108
  - test/test_kthxbye.rb
109
+ - test/redis-test.conf
110
+ - test/test_helper.rb
111
+ - test/test_failure.rb
213
112
  - test/test_worker.rb
113
+ - test/helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,33 +0,0 @@
1
- # rcov generated
2
- coverage
3
-
4
- # rdoc generated
5
- rdoc
6
-
7
- # yard generated
8
- doc
9
- .yardoc
10
-
11
- # bundler
12
- .bundle
13
-
14
- # jeweler generated
15
- pkg
16
- ## MAC OS
17
- .DS_Store
18
-
19
- ## TEXTMATE
20
- *.tmproj
21
- tmtags
22
-
23
- ## EMACS
24
- *~
25
- \#*
26
- .\#*
27
-
28
- ## VIM
29
- *.swp
30
- *.swo
31
-
32
- ## PROJECT::SPECIFIC
33
- *.gemspec
data/Gemfile.lock DELETED
@@ -1,28 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.5.0.pre3)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rack (1.2.1)
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- redis (2.0.10)
13
- shoulda (2.11.3)
14
- sinatra (1.0)
15
- rack (>= 1.0)
16
- yajl-ruby (0.7.7)
17
-
18
- PLATFORMS
19
- ruby
20
-
21
- DEPENDENCIES
22
- bundler (~> 1.0.0)
23
- jeweler (~> 1.5.0.pre3)
24
- rcov
25
- redis
26
- shoulda
27
- sinatra
28
- yajl-ruby
data/Rakefile DELETED
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = "kthxbye"
15
- gem.summary = %Q{Async processing + results notification}
16
- gem.description = %Q{Kthxbye is the answer to a fairly unique-yet-common problem: Background job processing when we care about the result.}
17
- gem.email = "hungerandthirst@gmail.com"
18
- gem.homepage = "http://github.com/plukevdh/kthxbye"
19
- gem.authors = ["Luke van der Hoeven"]
20
- end
21
- Jeweler::RubygemsDotOrgTasks.new
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:test) do |test|
24
- test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/test_*.rb'
26
- test.verbose = true
27
- end
28
-
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
-
36
- task :default => :test
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "kthxbye #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.5