hawking 0.1 → 0.2

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: 3dc5cdf9adf6ca786efe48dbd040d7b00583f5b9
4
- data.tar.gz: 80267e423e17f81fa36649c31bdf1a1d4f37a71c
3
+ metadata.gz: bfaf1499ae4d60b4d120b7cbbbcaf4e3857b2ee5
4
+ data.tar.gz: 7838b9bd81fc9143683142e0ef157c4bdd540d0d
5
5
  SHA512:
6
- metadata.gz: 0252cd0ee608b20e548627af88bb68c135bba7cf2bc77866f52240e9c865a1a005db59273f9254e03bea9314ced2a7cf1e73df00a893915131f561ff2a03ecd5
7
- data.tar.gz: 0dbbd239b80976bec8b258e72940ee36588e83a4c94960c9ad59e7c777cf451f274c0b5e4001ea9d09eef963326595b1d05c24847cbc9d2aafddb3fd0598ad81
6
+ metadata.gz: 40a663df64d4103861171fe57b2519d30a15b5387bc378cea54bc4ebdd446dbcc36dde015221659de0b81d124aafe3cc609b89cb01c97522a5e1a95ad8718b1d
7
+ data.tar.gz: ec308bad645f9efcdc537b94000ba3fdc04302f93e994c169316a9fe83d2b022fe9f0212bb32e328dc28708019d1c6636b96a451dd33d23784c4bd977c86406c
data/README.md CHANGED
@@ -1,37 +1,44 @@
1
1
  Hawking
2
2
  =======
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/hawking.png)](http://badge.fury.io/rb/hawking)
4
5
  [![Build Status](https://travis-ci.org/rogeriozambon/hawking.png?branch=master)](https://travis-ci.org/rogeriozambon/hawking)
5
6
  [![Code Climate](https://codeclimate.com/github/rogeriozambon/hawking.png)](https://codeclimate.com/github/rogeriozambon/hawking)
6
7
 
7
- Background job queueing using Socket. Inspired in the [Stalkeg gem](https://github.com/han/stalker).
8
+ Background job queueing using TCPSocket. Inspired in the [Stalker gem](https://github.com/han/stalker).
8
9
 
9
10
  Queueing jobs
10
11
  -------------
11
12
 
12
13
  From anywhere in your app:
13
14
 
14
- require 'hawking'
15
+ ~~~.ruby
16
+ require 'hawking'
15
17
 
16
- Hawking::Queue.new('email.send', :to => 'joe@example.com')
17
- Hawking::Queue.new('post.cleanup', :id => post.id)
18
+ hawking = Hawking::Queue.new
19
+
20
+ hawking.put 'email.send', to: 'joe@example.com'
21
+ hawking.put 'post.cleanup', id: post.id
22
+ ~~~
18
23
 
19
24
  Working jobs
20
25
  ------------
21
26
 
22
27
  In a standalone file, typically jobs.rb or worker.rb:
23
28
 
24
- require 'hawking'
29
+ ~~~.ruby
30
+ require 'hawking'
25
31
 
26
- extend Hawking
32
+ extend Hawking
27
33
 
28
- job 'email.send' do |args|
29
- Pony.send(:to => args['to'], :subject => "Hello there")
30
- end
34
+ job 'email.send' do |data|
35
+ Pony.send(to: data[:to], subject: "Hello there")
36
+ end
31
37
 
32
- job 'post.cleanup' do |args|
33
- Post.find(args['id']).cleanup
34
- end
38
+ job 'post.cleanup' do |data|
39
+ Post.find(data[:id]).cleanup
40
+ end
41
+ ~~~
35
42
 
36
43
  Running
37
44
  -------
@@ -40,18 +47,15 @@ Hawking:
40
47
 
41
48
  $ sudo gem install hawking
42
49
 
43
- Now run a worker using the stalk binary:
50
+ Now run a worker using the binary:
44
51
 
45
52
  $ hawking jobs.rb
46
53
  Working 2 jobs: [ email.send post.cleanup ]
47
- Working send.email (email=hello@example.com)
48
-
49
- Hawk will log to stdout as it starts working each job.
50
54
 
51
- Filter to a list of jobs you wish to run with an argument:
55
+ Working send.email ({:to=>joe@example.com})
56
+ Working post.cleanup ({:id=>1})
52
57
 
53
- $ hawking jobs.rb email.send
54
- Working 1 jobs: [ email.send ]
58
+ Hawking will log to stdout as it starts working each job.
55
59
 
56
60
  Running the tests
57
61
  -----------------
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new :spec
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["--colour", "--format documentation"]
6
+ end
5
7
 
8
+ desc "Default build will run specs"
6
9
  task default: :spec
data/bin/hawking CHANGED
@@ -2,13 +2,10 @@
2
2
  STDERR.sync = STDOUT.sync = true
3
3
 
4
4
  require "hawking"
5
- extend Hawking
6
-
7
- usage = "hawking <jobs.rb> [<job>[,<job>,..]]"
8
5
 
9
- file = ARGV.shift or abort usage
10
- jobs = ARGV.shift.split(',') rescue nil
6
+ extend Hawking
11
7
 
8
+ file = ARGV.shift or abort "hawking <jobs.rb>"
12
9
  file = "./#{file}" unless file.match(/^[\/.]/)
13
10
 
14
11
  require file
data/examples/enqueue.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require "hawking"
2
2
 
3
3
  hawking = Hawking::Queue.new
4
- hawking.put "send.email", :email => "hello@example.com"
4
+ hawking.put "send.email", email: "hello@example.com"
data/hawking.gemspec CHANGED
@@ -9,8 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Rogério Zambon"]
10
10
  s.email = ["rogeriozambon@gmail.com"]
11
11
  s.homepage = "http://github.com/rogeriozambon/hawking"
12
- s.summary = "Background job queueing using Socket. Inspired in the Stalkeg gem."
12
+ s.summary = "Background job queueing using TCPSocket. Inspired in the Stalkeg gem."
13
13
  s.description = s.summary
14
+ s.license = "MIT"
14
15
 
15
16
  s.executables = ["hawking"]
16
17
 
data/lib/hawking.rb CHANGED
@@ -5,10 +5,10 @@ require "timeout"
5
5
  module Hawking
6
6
  extend self
7
7
 
8
- VERSION = "0.1"
8
+ VERSION = "0.2"
9
9
 
10
10
  def run
11
- puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]"
11
+ puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]\r\r"
12
12
 
13
13
  server = TCPServer.open "127.0.0.1", 4481
14
14
 
@@ -17,17 +17,17 @@ module Hawking
17
17
 
18
18
  def work_jobs(server)
19
19
  Thread.start(server.accept) do |listener|
20
- job = JSON.parse listener.gets, symbolize_names: true
20
+ begin
21
+ Timeout::timeout(20) do
22
+ puts "Working on #{job[:queue]} (#{job[:data]})\r"
21
23
 
22
- puts "Working on #{job[:queue]} (#{job[:data]})"
24
+ job = JSON.parse listener.gets, symbolize_names: true
23
25
 
24
- begin
25
- Timeout::timeout(120) do
26
26
  handler = @@jobs[job[:queue]]
27
27
  handler.call(job[:data])
28
28
  end
29
29
  rescue Timeout::Error
30
- raise "The job hit 120 seconds timeout"
30
+ raise "The job hit 20 seconds timeout"
31
31
  end
32
32
  end
33
33
  end
@@ -47,7 +47,7 @@ module Hawking
47
47
  end
48
48
 
49
49
  def put(queue, data)
50
- info = JSON.generate :queue => queue, :data => data
50
+ info = JSON.generate queue: queue, data: data
51
51
 
52
52
  @socket.write info
53
53
  @socket.close
data/spec/hawking_spec.rb CHANGED
@@ -2,12 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe "Hawking" do
4
4
  before do
5
- $stdout.stub(:write).and_return ""
5
+ $stdout.stub(:write).and_return nil
6
6
  end
7
7
 
8
8
  it "storing a job" do
9
9
  Hawking.job "example" do |data|
10
- puts "Some example with #{data}"
10
+ puts "Some example with #{data.inspect}"
11
11
  end
12
12
 
13
13
  jobs = Hawking.jobs
@@ -22,7 +22,7 @@ describe "Hawking" do
22
22
  server = TCPServer.open "127.0.0.1", 4481
23
23
 
24
24
  hawking = Hawking::Queue.new
25
- hawking.put "example", :data => "john@example.org"
25
+ hawking.put "example", data: "john@example.org"
26
26
 
27
27
  data = JSON.parse server.accept.gets, symbolize_names: true
28
28
 
@@ -37,13 +37,13 @@ describe "Hawking" do
37
37
 
38
38
  it "works" do
39
39
  Hawking.job "example" do |data|
40
- puts "Some example with #{data}"
40
+ puts "Some example with #{data.inspect}"
41
41
  end
42
42
 
43
43
  server = TCPServer.open "127.0.0.1", 4481
44
44
 
45
45
  hawking = Hawking::Queue.new
46
- hawking.put "example", :data => "john@example.org"
46
+ hawking.put "example", data: "john@example.org"
47
47
 
48
48
  Hawking.work_jobs server
49
49
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hawking
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogério Zambon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-12 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Background job queueing using Socket. Inspired in the Stalkeg gem.
55
+ description: Background job queueing using TCPSocket. Inspired in the Stalkeg gem.
56
56
  email:
57
57
  - rogeriozambon@gmail.com
58
58
  executables:
@@ -60,7 +60,6 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .rspec
64
63
  - .travis.yml
65
64
  - Gemfile
66
65
  - Gemfile.lock
@@ -74,7 +73,8 @@ files:
74
73
  - spec/hawking_spec.rb
75
74
  - spec/spec_helper.rb
76
75
  homepage: http://github.com/rogeriozambon/hawking
77
- licenses: []
76
+ licenses:
77
+ - MIT
78
78
  metadata: {}
79
79
  post_install_message:
80
80
  rdoc_options: []
@@ -95,5 +95,5 @@ rubyforge_project:
95
95
  rubygems_version: 2.1.10
96
96
  signing_key:
97
97
  specification_version: 4
98
- summary: Background job queueing using Socket. Inspired in the Stalkeg gem.
98
+ summary: Background job queueing using TCPSocket. Inspired in the Stalkeg gem.
99
99
  test_files: []
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color --format documentation