faktory_worker_ruby 0.7.1 → 0.8.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: 5d427c1c0dc267c3debcf7fd725fab9a628f7d0d
4
- data.tar.gz: 92c6b2099292bc46e2eaf22ba3be5c9f3dadf6b0
3
+ metadata.gz: 5ffc1c6d5392fd64f4463ae4a47972f7d2c13ebc
4
+ data.tar.gz: cc1e0294bc5c333f7ce684f112ee1182e20d2095
5
5
  SHA512:
6
- metadata.gz: e856cbcb98527d2b38c000d87cfbced657f42b7956a7090014946c9131b4771f239683df586c084ad17b4e2f07f2e7f9560c62f7f438db99c523e276136540a6
7
- data.tar.gz: 44ce04a5b7346b1e8965b917ac9ecaad179936b62fb7dc4107e1cd9fe2155da0ff549c2ef91551c5f18b75daeec5f87a5aa8b38b4b628c3ab9ef4ba0147eb776
6
+ metadata.gz: 9f2a3b5f59d0a50c77f0f22ec86f291289762ba5e27dc012fa9cce34807883aee616b7ca9b7a937139b67137725f450c0e7fc504909f0a84136ebd4b6e67586e
7
+ data.tar.gz: 7ef1fd93ff1d803bb7d895d63749a3deb9cd4fe4000936df5b8e1facfca884e22e439574979b821972936b16b1ea15ef31f97c3db306b90b4d7514ea214d1437
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: required
2
+
3
+ language: ruby
4
+
5
+ services:
6
+ - docker
7
+
8
+ before_install:
9
+ - docker pull contribsys/faktory:latest
10
+ - docker run -d -p 127.0.0.1:7419:7419 -p 127.0.0.1:7420:7420 contribsys/faktory:latest /faktory -b :7419 -w :7420
11
+ - docker ps -a
data/Changes.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Changes
2
2
 
3
- ## 0.7.1
3
+ ## 0.8.0
4
+
5
+ - Add `-l LABEL` argument for adding labels to a process [#27, jpwinans]
6
+ - Support the quiet and shutdown heartbeat signals from the server [#28]
4
7
 
5
- - Add an ActiveJob adapter for Faktory.
8
+ ## 0.7.1
6
9
 
7
- [#17, jagthedrummer]
10
+ - Add an ActiveJob adapter for FWR. [#17, jagthedrummer]
8
11
 
9
12
  ## 0.7.0
10
13
 
data/Gemfile.lock CHANGED
@@ -1,29 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faktory_worker_ruby (0.7.1)
4
+ faktory_worker_ruby (0.8.0)
5
5
  connection_pool (~> 2.2, >= 2.2.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activejob (5.1.5)
11
- activesupport (= 5.1.5)
10
+ activejob (5.2.1)
11
+ activesupport (= 5.2.1)
12
12
  globalid (>= 0.3.6)
13
- activesupport (5.1.5)
13
+ activesupport (5.2.1)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (~> 0.7)
15
+ i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
17
17
  tzinfo (~> 1.1)
18
18
  concurrent-ruby (1.0.5)
19
- connection_pool (2.2.1)
19
+ connection_pool (2.2.2)
20
20
  globalid (0.4.1)
21
21
  activesupport (>= 4.2.0)
22
- i18n (0.9.5)
22
+ i18n (1.1.0)
23
23
  concurrent-ruby (~> 1.0)
24
- minitest (5.10.3)
25
- minitest-hooks (1.4.2)
26
- rake (12.1.0)
24
+ minitest (5.11.3)
25
+ minitest-hooks (1.5.0)
26
+ minitest (> 5.3)
27
+ rake (12.3.1)
27
28
  thread_safe (0.3.6)
28
29
  tzinfo (1.2.5)
29
30
  thread_safe (~> 0.1)
@@ -39,4 +40,4 @@ DEPENDENCIES
39
40
  rake (~> 12)
40
41
 
41
42
  BUNDLED WITH
42
- 1.16.0
43
+ 1.16.3
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # faktory\_worker\_ruby
2
2
 
3
+ ![travis](https://travis-ci.org/contribsys/faktory_worker_ruby.svg?branch=master)
4
+
3
5
  Faktory\_worker\_ruby is the official Ruby client and worker process for the
4
6
  Faktory background job server. It is similar to [Sidekiq](http://sidekiq.org).
5
7
 
@@ -11,34 +11,29 @@ module ActiveJob
11
11
  # Rails.application.config.active_job.queue_adapter = :faktory
12
12
  class FaktoryAdapter
13
13
  def enqueue(job) #:nodoc:
14
- jid = SecureRandom.hex(12)
15
- job.provider_job_id = jid
16
- # Faktory::Client does not support symbols as keys
17
- Faktory::Client.new.push \
18
- "jid" => jid,
19
- "jobtype" => JobWrapper,
20
- "custom" => {
21
- "wrapped" => job.class.to_s,
22
- },
23
- "priority" => job.priority,
24
- "queue" => job.queue_name,
25
- "args" => [ job.serialize ]
14
+ enqueue_at(job, nil)
26
15
  end
27
16
 
28
17
  def enqueue_at(job, timestamp) #:nodoc:
29
18
  jid = SecureRandom.hex(12)
30
19
  job.provider_job_id = jid
31
- # Faktory::Client does not support symbols as keys
32
- Faktory::Client.new.push \
20
+ hash = {
33
21
  "jid" => jid,
34
- "jobtype" => JobWrapper,
22
+ "jobtype" => JobWrapper.to_s,
35
23
  "custom" => {
36
- "wrapped" => job.class.to_s
24
+ "wrapped" => job.class.to_s,
37
25
  },
38
- "priority" => job.priority,
39
26
  "queue" => job.queue_name,
40
27
  "args" => [ job.serialize ],
41
- "at" => Time.at(timestamp).utc.to_datetime.rfc3339(9)
28
+ }
29
+ opts = job.faktory_options_hash.dup
30
+ hash["at"] = Time.at(timestamp).utc.to_datetime.rfc3339(9) if timestamp
31
+ if opts.size > 0
32
+ hash["retry"] = opts.delete("retry") if opts.has_key?("retry")
33
+ hash["custom"] = opts.merge(hash["custom"])
34
+ end
35
+ # Faktory::Client does not support symbols as keys
36
+ Faktory::Client.new.push(hash)
42
37
  end
43
38
 
44
39
  class JobWrapper #:nodoc:
@@ -50,4 +45,13 @@ module ActiveJob
50
45
  end
51
46
  end
52
47
  end
48
+
49
+ class Base
50
+ class_attribute :faktory_options_hash
51
+ self.faktory_options_hash = {}
52
+
53
+ def self.faktory_options(hsh)
54
+ self.faktory_options_hash = self.faktory_options_hash.stringify_keys.merge(hsh.stringify_keys)
55
+ end
56
+ end
53
57
  end
data/lib/faktory/cli.rb CHANGED
@@ -235,6 +235,10 @@ module Faktory
235
235
  opts[:tag] = arg
236
236
  end
237
237
 
238
+ o.on '-l', '--label LABEL', "Process label to use in Faktory UI" do |arg|
239
+ (opts[:labels] ||= []) << arg
240
+ end
241
+
238
242
  o.on "-q", "--queue QUEUE[,WEIGHT]", "Queues to process with optional weights" do |arg|
239
243
  queue, weight = arg.split(",")
240
244
  parse_queue opts, queue, weight
@@ -1,6 +1,7 @@
1
1
  require 'socket'
2
2
  require 'json'
3
3
  require 'uri'
4
+ require 'digest'
4
5
  require 'securerandom'
5
6
 
6
7
  module Faktory
@@ -148,7 +149,7 @@ module Faktory
148
149
  "wid": @@random_process_wid,
149
150
  "hostname": Socket.gethostname,
150
151
  "pid": $$,
151
- "labels": ["ruby-#{RUBY_VERSION}"],
152
+ "labels": Faktory.options[:labels] || ["ruby-#{RUBY_VERSION}"],
152
153
  "v": 2,
153
154
  }
154
155
 
@@ -55,7 +55,17 @@ module Faktory
55
55
  $0 = PROCTITLES.map {|p| p.call }.join(" ")
56
56
 
57
57
  begin
58
- Faktory.server {|c| c.beat }
58
+ result = Faktory.server {|c| c.beat }
59
+ case result
60
+ when "OK"
61
+ # all good
62
+ when "terminate"
63
+ ::Process.kill('TERM', $$)
64
+ when "quiet"
65
+ ::Process.kill('TSTP', $$)
66
+ else
67
+ Faktory.logger.warn "Got unexpected BEAT: #{result}"
68
+ end
59
69
  rescue => ex
60
70
  # best effort, try again in a few secs
61
71
  end
@@ -29,8 +29,8 @@ module Faktory
29
29
  def self.job_hash_context(job_hash)
30
30
  # If we're using a wrapper class, like ActiveJob, use the "wrapped"
31
31
  # attribute to expose the underlying thing.
32
- klass = job_hash['wrapped'.freeze] || job_hash["jobtype".freeze]
33
- "#{klass} JID-#{job_hash['jid'.freeze]}"
32
+ klass = job_hash['custom']['wrapped'] || job_hash["jobtype"]
33
+ "#{klass} JID-#{job_hash['jid']}"
34
34
  end
35
35
 
36
36
  def self.with_job_hash_context(job_hash, &block)
@@ -19,10 +19,8 @@ module Faktory::Middleware::I18n
19
19
  # Pull the msg locale out and set the current thread to use it.
20
20
  class Worker
21
21
  def call(jobinst, payload)
22
- I18n.locale = payload.dig("custom", "locale") || I18n.default_locale
23
- yield
24
- ensure
25
- I18n.locale = I18n.default_locale
22
+ locale = payload.dig("custom", "locale") || I18n.default_locale
23
+ I18n.with_locale(locale) { yield }
26
24
  end
27
25
  end
28
26
  end
data/lib/faktory/rails.rb CHANGED
@@ -20,6 +20,10 @@ module Faktory
20
20
  # None of this matters on the client-side, only within the Faktory executor itself.
21
21
  #
22
22
  Faktory.configure_worker do |_|
23
+ if ::Rails::VERSION::MAJOR < 5
24
+ raise "Your current version of Rails, #{::Rails::VERSION::STRING}, is not supported"
25
+ end
26
+
23
27
  Faktory.options[:reloader] = Faktory::Rails::Reloader.new
24
28
  end
25
29
  end
@@ -40,4 +44,11 @@ module Faktory
40
44
  end
41
45
  end
42
46
  end if defined?(::Rails)
47
+
48
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR < 5
49
+ $stderr.puts("**************************************************")
50
+ $stderr.puts("🚫 ERROR: Faktory Worker does not support Rails versions under 5.x - please ensure your workers are updated")
51
+ $stderr.puts("**************************************************")
52
+ $stderr.puts("")
53
+ end
43
54
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Faktory
3
- VERSION = "0.7.1"
3
+ VERSION = "0.8.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faktory_worker_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -95,6 +95,7 @@ extensions: []
95
95
  extra_rdoc_files: []
96
96
  files:
97
97
  - ".gitignore"
98
+ - ".travis.yml"
98
99
  - Changes.md
99
100
  - Gemfile
100
101
  - Gemfile.lock
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  version: '0'
144
145
  requirements: []
145
146
  rubyforge_project:
146
- rubygems_version: 2.5.1
147
+ rubygems_version: 2.6.13
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Ruby worker for Faktory