localjob 0.1.0 → 0.1.1

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: 3f5d7728e5e75545f1d311af3eb4e255bcbe30df
4
- data.tar.gz: 1f5fcded093681ad2a958b53b7d3736bde363143
3
+ metadata.gz: f1b3b73b7b6d29292e899fbc6e3dd8ec230bfd8c
4
+ data.tar.gz: 18b94b58722de37178649a63ec0ce04e269295a2
5
5
  SHA512:
6
- metadata.gz: dd25abafa772e5054f214a13a0143580efb81ab942a2d8406aa2ca4872881b82553dfa36bc7da50a407ce3ff77d863b581781fd5f802cdf053b6b3b6872e2439
7
- data.tar.gz: 8ffec91938da80ad655ea0b95e8238b9a7eb2eeff8e44eb56bc11fdd257202677733dc4ef5ba431fa61878b2260a03dbc1ce4e4f4b905229edc3437caab9b1c0
6
+ metadata.gz: 1fed832f36a4f04b3f4ce3c606090c88868d5c9d3556e5db0276033bc2819be697c947f5454d750c8aab59f91b6c039af809feffb9383c98533a29a3dc6dd91c
7
+ data.tar.gz: 62861fd26776063bedd58f77593c15ec75ff76ed818f87b703493a8d5dd0c51f3e9991a22c663f609df380e91ced6598a892d780c95c753fce052900f1c35f62
data/README.md CHANGED
@@ -102,7 +102,8 @@ Create your instance of the queue as normal in your setup:
102
102
 
103
103
  ```ruby
104
104
  def setup
105
- @queue = LocalJob.new("test-queue")
105
+ @queue = Localjob.new("test-queue")
106
+ @worker = Localjob::Worker.new("test-queue")
106
107
  end
107
108
  ```
108
109
 
@@ -10,13 +10,6 @@ class Localjob
10
10
  @queues << queue_from_name(queue)
11
11
  end
12
12
 
13
- def shift
14
- (queue,), = IO.select(@queues)
15
- queue.shift
16
- rescue POSIX::Mqueue::QueueEmpty
17
- retry
18
- end
19
-
20
13
  private
21
14
  def queue_from_name(queue)
22
15
  queue.instance_of?(Localjob) ? queue : Localjob.new(queue)
@@ -1,6 +1,15 @@
1
1
  require 'posix/mqueue'
2
2
 
3
3
  class Localjob
4
+ class Channel
5
+ def shift
6
+ (queue,), = IO.select(@queues)
7
+ queue.shift
8
+ rescue POSIX::Mqueue::QueueEmpty
9
+ retry
10
+ end
11
+ end
12
+
4
13
  class LinuxAdapter
5
14
  attr_reader :mqueue
6
15
 
@@ -10,36 +10,38 @@ class Localjob
10
10
 
11
11
  class SysvAdapter
12
12
  include SysVIPC
13
- attr_reader :mqueue
14
13
 
15
14
  def initialize(name)
16
15
  @filename = "/tmp/#{name}"
17
- File.open(@filename, "w") { }
18
- key = ftok(@filename, 0)
19
-
20
- @mq = MessageQueue.new(key, IPC_CREAT | 0600)
16
+ end
17
+
18
+ def mq
19
+ unless @mq
20
+ File.open(@filename, "w") { }
21
+ key = ftok(@filename, 0)
22
+
23
+ @mq = MessageQueue.new(key, IPC_CREAT | 0600)
24
+ end
25
+
26
+ @mq
21
27
  end
22
28
 
23
29
  def receive
24
- @mq.receive(0, 8024)
30
+ mq.receive(0, 8024)
25
31
  end
26
32
 
27
33
  def send(message)
28
- @mq.send(1, message)
34
+ mq.send(1, message)
29
35
  end
30
36
 
31
37
  def size
32
- @mq.ipc_stat.msg_qnum
38
+ mq.ipc_stat.msg_qnum
33
39
  end
34
40
 
35
41
  def destroy
36
42
  File.delete(@filename)
37
43
  @mq.rm
38
- end
39
-
40
- private
41
- def fix_queue_name(name)
42
- name.start_with?('/') ? name : "/#{name}"
44
+ @mq = nil
43
45
  end
44
46
  end
45
47
  end
@@ -1,3 +1,3 @@
1
1
  class Localjob
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/localjob.rb CHANGED
@@ -6,6 +6,13 @@ require "localjob/version"
6
6
  require 'localjob/channel'
7
7
  require 'localjob/worker'
8
8
 
9
+ case RUBY_PLATFORM
10
+ when /linux/
11
+ require 'localjob/linux_adapter'
12
+ else
13
+ require 'localjob/sysv_adapter'
14
+ end
15
+
9
16
  class Localjob
10
17
  extend Forwardable
11
18
 
@@ -27,10 +34,8 @@ class Localjob
27
34
 
28
35
  case RUBY_PLATFORM
29
36
  when /linux/
30
- require 'localjob/linux_adapter'
31
37
  @queue = LinuxAdapter.new(@name)
32
38
  else
33
- require 'localjob/sysv_adapter'
34
39
  @queue = SysvAdapter.new(@name)
35
40
  end
36
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -142,4 +142,3 @@ test_files:
142
142
  - test/mock_adapter.rb
143
143
  - test/test_helper.rb
144
144
  - test/worker_test.rb
145
- has_rdoc: