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 +4 -4
- data/Gemfile +3 -0
- data/README.md +3 -3
- data/lib/localjob/version.rb +1 -1
- data/lib/localjob/worker.rb +0 -5
- data/lib/localjob.rb +1 -1
- data/test/sysv_adapter_test.rb +6 -0
- data/test/test_helper.rb +3 -0
- data/test/worker_test.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f40a0417920e5c4e5ef5bc6cdb5586f09f67e2a
|
4
|
+
data.tar.gz: 3851bec9273ffdbb4c30ea47010588e51af98b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d80362eb2ee2f24eef60f7500cf22d692222dd6ef7bccdda64f44c6b0a853bc84b4fb84542aadd2ba3ceaaf7320f197c5c31ec4cf2b6719c055fd8344e0682f9
|
7
|
+
data.tar.gz: 27a5dec0c5281dd20fd698eefd99487203ff764fa13ca777a0046fc744639e62b1ff0c5c0ec7eedfee2e4ee418e0dc60c60b598778574c28aaefaefe906465c0
|
data/Gemfile
CHANGED
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) [![
|
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
|
88
|
-
@worker = Localjob::Worker.new(
|
87
|
+
@queue = Localjob.new
|
88
|
+
@worker = Localjob::Worker.new(@queue)
|
89
89
|
end
|
90
90
|
```
|
91
91
|
|
data/lib/localjob/version.rb
CHANGED
data/lib/localjob/worker.rb
CHANGED
@@ -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
data/test/sysv_adapter_test.rb
CHANGED
@@ -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
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
|
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
|