localjob 0.4.0 → 0.4.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: 3f40a0417920e5c4e5ef5bc6cdb5586f09f67e2a
4
- data.tar.gz: 3851bec9273ffdbb4c30ea47010588e51af98b98
3
+ metadata.gz: 162114bce1539ca945710b05070111780c6b4aa4
4
+ data.tar.gz: 8c3d1941d8e4f4a709aee68dcbbc15008bbe86b2
5
5
  SHA512:
6
- metadata.gz: d80362eb2ee2f24eef60f7500cf22d692222dd6ef7bccdda64f44c6b0a853bc84b4fb84542aadd2ba3ceaaf7320f197c5c31ec4cf2b6719c055fd8344e0682f9
7
- data.tar.gz: 27a5dec0c5281dd20fd698eefd99487203ff764fa13ca777a0046fc744639e62b1ff0c5c0ec7eedfee2e4ee418e0dc60c60b598778574c28aaefaefe906465c0
6
+ metadata.gz: 94919e17376f5b869d7eac9a7ead522ca3aedf967ff8431019463487138b5b43b127021d63036adff9510a8664794c09e0c88e35f8618d43f9b4d0e03a3a9df3
7
+ data.tar.gz: 5bc9fd26d206583f8c7a23a895dd0cc6107a7ee51dd8fecdfa157bd5aaadde1e67ca4d81dc43a0a090ecbf81e8c19000862f913890df5f090b0abe8a27b72872
data/README.md CHANGED
@@ -3,7 +3,8 @@
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
5
5
  app pushing to the queue must reside on the same machine. It's the sqlite of
6
- background queues. Here's a post about [how it works][blog].
6
+ background queues. Here's a post about [how it works][blog]. You can run
7
+ Localjob either as a seperate process, or as a thread in your app.
7
8
 
8
9
  Localjob is for early-development situations where you don't need a
9
10
  full-featured background queue, but just want to get started with something
@@ -16,7 +17,7 @@ Localjob works on Ruby >= 2.0.0 on Linux and OS X.
16
17
  Add it to your Gemfile:
17
18
 
18
19
  ```ruby
19
- gem 'localjob', "~> 0.2"
20
+ gem 'localjob'
20
21
  ```
21
22
 
22
23
  ## Usage
@@ -67,6 +68,24 @@ BackgroundQueue << EmailJob.new(current_user.id, welcome_email)
67
68
 
68
69
  ### Managing workers
69
70
 
71
+ There are two ways to spawn workers, either a thread inside the process emitting
72
+ events, or as a separate process managed with the `localjob` command-line
73
+ utility.
74
+
75
+ #### Thread
76
+
77
+ Spawn the worker thread in an initializer where you are initializing Localjob as
78
+ well:
79
+
80
+ ```ruby
81
+ BackgroundQueue = Localjob.new
82
+
83
+ worker = Localjob::Worker.new(BackgroundQueue, logger: Rails.logger)
84
+ worker.work(thread: true)
85
+ ```
86
+
87
+ #### Process
88
+
70
89
  Spawning workers can be done with `localjob`. Run `localjob work` to spawn a
71
90
  single worker. It takes a few arguments. The most important being `--require`
72
91
  which takes a path the worker will require before processing jobs. For Rails,
@@ -114,5 +133,19 @@ def test_pop_and_send_to_worker
114
133
  end
115
134
  ```
116
135
 
136
+ ### Multiple queues
137
+
138
+ If you wish to have multiple queues you can have multiple Localjob objects
139
+ referencing different queues. A worker can only work off a single queue at a
140
+ time, so you will have to spawn multiple thread or process workers. Example:
141
+
142
+ ```ruby
143
+ MailQueue = Localjob.new(0xDEADC0DE)
144
+ DefaultQueue = Localjob.new(0xDEADCAFE)
145
+ ```
146
+
147
+ Note that Localjob takes a hex value as the queue name. This is how the SysV
148
+ adapter identifies different queues.
149
+
117
150
  [sysv]: http://man7.org/linux/man-pages/man7/svipc.7.html
118
151
  [blog]: http://sirupsen.com/unix-background-queue/
data/lib/localjob/cli.rb CHANGED
@@ -5,11 +5,10 @@ class Localjob
5
5
  option :queue, aliases: ["-q"], type: :string, default: "0x10CA110B"
6
6
  option :require, aliases: ["-r"], type: :string, default: "."
7
7
  option :pid_file, aliases: ["-p"], type: :string
8
- option :daemon, aliases: ["-d"], type: :boolean
9
8
  desc "work", "Start worker to process jobs"
10
9
  def work
11
10
  load_environment options[:require]
12
- Localjob::Worker.new(options[:queue].to_i(16), *options.slice(:daemon, :pid_file)).work
11
+ Localjob::Worker.new(options[:queue].to_i(16), *options.slice(:pid_file)).work
13
12
  end
14
13
 
15
14
  private
@@ -20,6 +19,15 @@ class Localjob
20
19
  ::Rails.application.eager_load!
21
20
  elsif File.file?(file)
22
21
  require File.expand_path(file)
22
+ else
23
+ puts <<EOS
24
+ To run a localjob worker, you must supply the --require flag. This is the file
25
+ the worker requires before working off jobs.
26
+
27
+ Otherwise localjob will complain about undefined classes, because they are not
28
+ loaded in the context of the worker.
29
+ EOS
30
+ exit!
23
31
  end
24
32
  end
25
33
 
@@ -1,3 +1,3 @@
1
1
  class Localjob
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -81,6 +81,7 @@ class Localjob
81
81
  def trap_signals
82
82
  Signal.trap("QUIT") { shutdown }
83
83
  Signal.trap("INT") { shutdown }
84
+ Signal.trap("TERM") { shutdown }
84
85
  end
85
86
 
86
87
  def create_pid_file(path)
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen