localjob 0.3.0 → 0.4.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: 0917b722ab080a63864457aa154296a191d095ec
4
- data.tar.gz: f15b71a3239ae2fd38cba2861c02d61b33b4c019
3
+ metadata.gz: 3f40a0417920e5c4e5ef5bc6cdb5586f09f67e2a
4
+ data.tar.gz: 3851bec9273ffdbb4c30ea47010588e51af98b98
5
5
  SHA512:
6
- metadata.gz: 094f2204527babf51a1da02a0482826305c1510dac6c14e2ca75b7ad7417c8b00c60acb0242783edc24e866a4165ce3425ae909a6127623666aebfc71504ac95
7
- data.tar.gz: fb2f04ea2bd0c6510d9e3ce9d3f3cb6feb8b62cb99d132dff6976ff18871adf07ca67c9ac41e5e5b132281dc50e189867a72b800ffe9544b7efe89569563557e
6
+ metadata.gz: d80362eb2ee2f24eef60f7500cf22d692222dd6ef7bccdda64f44c6b0a853bc84b4fb84542aadd2ba3ceaaf7320f197c5c31ec4cf2b6719c055fd8344e0682f9
7
+ data.tar.gz: 27a5dec0c5281dd20fd698eefd99487203ff764fa13ca777a0046fc744639e62b1ff0c5c0ec7eedfee2e4ee418e0dc60c60b598778574c28aaefaefe906465c0
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in localjob.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
7
+ gem 'pry'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Localjob [![Build Status](https://travis-ci.org/Sirupsen/localjob.png?branch=master)](https://travis-ci.org/Sirupsen/localjob) [![Code Climate](https://codeclimate.com/github/Sirupsen/localjob.png)](https://codeclimate.com/github/Sirupsen/localjob)
1
+ # Localjob [![Build Status](https://travis-ci.org/Sirupsen/localjob.png?branch=master)](https://travis-ci.org/Sirupsen/localjob) [![Coverage Status](https://coveralls.io/repos/Sirupsen/localjob/badge.png?branch=master)](https://coveralls.io/r/Sirupsen/localjob?branch=master)
2
2
 
3
3
  Localjob is a simple, self-contained background queue built on top of [System V
4
4
  message queues][sysv] (SysV Message Queue => SysV MQ for short). Workers and the
@@ -84,8 +84,8 @@ Create your instance of the queue as normal in your setup:
84
84
 
85
85
  ```ruby
86
86
  def setup
87
- @queue = Localjob.new("test-queue")
88
- @worker = Localjob::Worker.new("test-queue")
87
+ @queue = Localjob.new
88
+ @worker = Localjob::Worker.new(@queue)
89
89
  end
90
90
  ```
91
91
 
@@ -1,3 +1,3 @@
1
1
  class Localjob
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -28,7 +28,6 @@ class Localjob
28
28
  return work_thread if thread
29
29
 
30
30
  create_pid_file(@options[:pid_file])
31
- deamonize if @options[:deamon]
32
31
 
33
32
  loop { break unless shift_and_process }
34
33
  end
@@ -84,10 +83,6 @@ class Localjob
84
83
  Signal.trap("INT") { shutdown }
85
84
  end
86
85
 
87
- def deamonize
88
- Process.daemon(true, true)
89
- end
90
-
91
86
  def create_pid_file(path)
92
87
  File.open(path, 'w') { |f| f << self.pid } if path
93
88
  end
data/lib/localjob.rb CHANGED
@@ -12,7 +12,7 @@ class Localjob
12
12
  attr_reader :name
13
13
  attr_accessor :queue
14
14
 
15
- def_delegators :queue, :to_io, :destroy, :size
15
+ def_delegators :queue, :stats, :destroy, :size
16
16
 
17
17
  # LOCALJOB in 1337speak
18
18
  def initialize(name = 0x10CA110B)
@@ -20,4 +20,10 @@ class SysvAdapterTest < LocaljobTestCase
20
20
  @localjob << "Hello World"
21
21
  assert_equal 1, @localjob.size
22
22
  end
23
+
24
+ def test_stats
25
+ @localjob << "Hello World"
26
+ assert_equal 20, @localjob.stats[:size]
27
+ assert_equal 1, @localjob.stats[:count]
28
+ end
23
29
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'minitest/unit'
2
5
  require 'minitest/autorun'
3
6
  $:<< File.dirname(__FILE__) + "/../lib"
data/test/worker_test.rb CHANGED
@@ -6,6 +6,10 @@ class WorkerTest < LocaljobTestCase
6
6
  @worker = worker(@localjob)
7
7
  end
8
8
 
9
+ def teardown
10
+ @localjob.destroy
11
+ end
12
+
9
13
  def test_pop_and_send_to_worker
10
14
  WalrusJob.any_instance.expects(:perform)
11
15
 
@@ -58,17 +62,21 @@ class WorkerTest < LocaljobTestCase
58
62
  sleep 0.1
59
63
 
60
64
  Process.kill("QUIT", pid)
65
+ sleep 0.1
61
66
 
62
67
  assert_equal 0, @localjob.size
63
68
  end
64
69
 
65
- def test_sigquit_terminates_the_worker
70
+ def test_sigint_terminates_the_worker
66
71
  @localjob << WalrusJob.new("move")
67
72
 
68
73
  pid = fork { @worker.work }
69
74
  sleep 0.1
70
75
 
71
76
  Process.kill("INT", pid)
77
+ sleep 0.1
78
+
79
+ assert_equal 0, @localjob.size
72
80
  end
73
81
 
74
82
  def test_thread_worker
@@ -82,4 +90,24 @@ class WorkerTest < LocaljobTestCase
82
90
 
83
91
  assert_equal 0, @localjob.size
84
92
  end
93
+
94
+ def test_kill_terminates_forked_worker
95
+ @localjob << WalrusJob.new("move")
96
+
97
+ assert_equal 1, @localjob.size
98
+
99
+ fork { @worker.work }
100
+ # Can do this immediately after, since it pushes a termination message to
101
+ # the queue.
102
+ @worker.kill
103
+ sleep 0.1
104
+
105
+ assert_equal 0, @localjob.size
106
+ end
107
+
108
+ def test_sending_termination_message_calls_shutdown!
109
+ @localjob << Localjob::Worker::TERMINATION_MESSAGE
110
+ @worker.expects(:exit!)
111
+ @worker.work
112
+ end
85
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen