faktory_worker_ruby 1.0.1 → 1.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
  SHA256:
3
- metadata.gz: 7739220174ff556abdf6a357cbcd260b6290c732628b27c8dc01ad00be727dd9
4
- data.tar.gz: 3c87db6e71078419a761c6b34dbdcdd3914d5551f4b42f04140a1621c6568b50
3
+ metadata.gz: 8ba3a7a6dbf71b034a2e9a209830f3049132c72b12105262b6ce971df9e602e6
4
+ data.tar.gz: f0adb0757fdaed227ec36d13786dadf7a9e39b6854589f4c25e65a8c9101cf86
5
5
  SHA512:
6
- metadata.gz: b2fc14441abfab58c7cde5401e42adcfe3bb558cd5d5dbf8f6a5db6b176cf2b1d9057370dd0b1daf3d3ca629bb829495bc53167e56e02f0543ec4f89556792ba
7
- data.tar.gz: 12b5d2fc13701e3c221b9ef8301bdb5b43806b1058336298393b66fc3f8020eb01d9569a43884a9f789a5df754bd24e987a340a74f12f055ae71a244d0d0763d
6
+ metadata.gz: 89471fb1dfd8624f9b562c773909378b4c40a4b52fd7dd198b7d2808199b2057a760b2cbcd919b8aa4494569979092c53762dd24e57be6ecfe7143a97540521d
7
+ data.tar.gz: 734b8145a57e435ecac307006723608998958bd9952a194c804fe033681579530d0ccc84ed591ffe8cfbbc5393abe4bd6b95045c49d02ceb3c87f742f6027905
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby: [2.5, 2.6, 2.7, '3.0']
15
+ runs-on: ubuntu-latest
16
+ services:
17
+ faktory:
18
+ image: contribsys/faktory:latest
19
+ ports:
20
+ - 7419:7419
21
+ - 7420:7420
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ bundler-cache: true
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - run: bundle install
29
+ - run: bundle exec rake
data/Changes.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changes
2
2
 
3
+ ## 1.1.1
4
+
5
+ - Fix OpenSSL error [#59]
6
+
7
+ ## 1.1.0
8
+
9
+ - Send process RSS to Faktory for /Busy page
10
+ - Implement QUEUE PAUSE/RESUME client commands
11
+ - Fix broken `complete` callback with batches
12
+
13
+ ## 1.0.3
14
+
15
+ - Fix corruption in `custom` hash elements [#55]
16
+
17
+ ## 1.0.2
18
+
19
+ - Fix "batch not open" errors
20
+
3
21
  ## 1.0.1
4
22
 
5
23
  - Run client middleware before pushing a job to Faktory [#48]
data/Gemfile.lock CHANGED
@@ -1,40 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faktory_worker_ruby (1.0.1)
4
+ faktory_worker_ruby (1.1.0)
5
5
  connection_pool (~> 2.2, >= 2.2.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activejob (6.0.3.2)
11
- activesupport (= 6.0.3.2)
10
+ activejob (6.1.3.2)
11
+ activesupport (= 6.1.3.2)
12
12
  globalid (>= 0.3.6)
13
- activesupport (6.0.3.2)
13
+ activesupport (6.1.3.2)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.2, >= 2.2.2)
19
- concurrent-ruby (1.1.6)
20
- connection_pool (2.2.3)
21
- docile (1.3.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ concurrent-ruby (1.1.9)
20
+ connection_pool (2.2.5)
21
+ docile (1.4.0)
22
22
  globalid (0.4.2)
23
23
  activesupport (>= 4.2.0)
24
- i18n (1.8.5)
24
+ i18n (1.8.10)
25
25
  concurrent-ruby (~> 1.0)
26
- minitest (5.14.1)
26
+ minitest (5.14.4)
27
27
  minitest-hooks (1.5.0)
28
28
  minitest (> 5.3)
29
- rake (13.0.1)
30
- simplecov (0.18.5)
29
+ rake (13.0.3)
30
+ simplecov (0.21.2)
31
31
  docile (~> 1.1)
32
32
  simplecov-html (~> 0.11)
33
- simplecov-html (0.12.2)
34
- thread_safe (0.3.6)
35
- tzinfo (1.2.7)
36
- thread_safe (~> 0.1)
37
- zeitwerk (2.4.0)
33
+ simplecov_json_formatter (~> 0.1)
34
+ simplecov-html (0.12.3)
35
+ simplecov_json_formatter (0.1.3)
36
+ tzinfo (2.0.4)
37
+ concurrent-ruby (~> 1.0)
38
+ zeitwerk (2.4.2)
38
39
 
39
40
  PLATFORMS
40
41
  ruby
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # faktory\_worker\_ruby
2
2
 
3
- ![travis](https://travis-ci.org/contribsys/faktory_worker_ruby.svg?branch=master)
3
+ ![CI status](https://github.com/contribsys/faktory_worker_ruby/actions/workflows/ci.yml/badge.svg)
4
4
 
5
5
  Faktory\_worker\_ruby is the official Ruby client and worker process for the
6
6
  Faktory background job server. It is similar to [Sidekiq](http://sidekiq.org).
@@ -16,6 +16,14 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Faktory::VERSION
17
17
  gem.required_ruby_version = ">= 2.5.0"
18
18
 
19
+ gem.metadata = {
20
+ "homepage_uri" => "https://contribsys.com/faktory",
21
+ "bug_tracker_uri" => "https://github.com/contribsys/faktory_worker_ruby/issues",
22
+ "documentation_uri" => "https://github.com/contribsys/faktory_worker_ruby/wiki",
23
+ "changelog_uri" => "https://github.com/contribsys/faktory_worker_ruby/blob/master/Changes.md",
24
+ "source_code_uri" => "https://github.com/contribsys/faktory_worker_ruby",
25
+ }
26
+
19
27
  gem.add_dependency 'connection_pool', '~> 2.2', ">= 2.2.2"
20
28
  gem.add_development_dependency 'activejob', '>= 5.2.0'
21
29
  gem.add_development_dependency 'minitest', '~> 5'
data/lib/faktory/batch.rb CHANGED
@@ -98,7 +98,7 @@ module Faktory
98
98
 
99
99
  def complete=(val)
100
100
  raise "Batch cannot be modified once created" if bid
101
- @success = to_callback(val)
101
+ @complete = to_callback(val)
102
102
  end
103
103
 
104
104
  def jobs(&block)
data/lib/faktory/cli.rb CHANGED
@@ -212,7 +212,7 @@ module Faktory
212
212
  if !File.exist?(options[:require]) ||
213
213
  (File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
214
214
  logger.info "=================================================================="
215
- logger.info " Please point Faktory to a Rails 5 application or a Ruby file "
215
+ logger.info " Please point Faktory to a Rails application or a Ruby file "
216
216
  logger.info " to load your worker classes with -r [DIR|FILE]."
217
217
  logger.info "=================================================================="
218
218
  logger.info @parser
@@ -80,9 +80,9 @@ module Faktory
80
80
  end
81
81
  batch.instance_variable_set(:@bid, bid)
82
82
 
83
- old = Thread.current["faktory_batch"]
84
- Thread.current["faktory_batch"] = batch
83
+ old = Thread.current[:faktory_batch]
85
84
  begin
85
+ Thread.current[:faktory_batch] = batch
86
86
  # any jobs pushed in this block will implicitly have
87
87
  # their `bid` attribute set so they are associated
88
88
  # with the current batch.
@@ -110,8 +110,8 @@ module Faktory
110
110
  ok
111
111
  end
112
112
  old = Thread.current[:faktory_batch]
113
- Thread.current[:faktory_batch] = b
114
113
  begin
114
+ Thread.current[:faktory_batch] = b
115
115
  # any jobs pushed in this block will implicitly have
116
116
  # their `bid` attribute set so they are associated
117
117
  # with the current batch.
@@ -141,6 +141,22 @@ module Faktory
141
141
  end
142
142
  end
143
143
 
144
+ def pause_queues(queues)
145
+ qs = Array(queues)
146
+ transaction do
147
+ command "QUEUE PAUSE", qs.join(" ")
148
+ ok
149
+ end
150
+ end
151
+
152
+ def resume_queues(queues)
153
+ qs = Array(queues)
154
+ transaction do
155
+ command "QUEUE RESUME", qs.join(" ")
156
+ ok
157
+ end
158
+ end
159
+
144
160
  # Push a hash corresponding to a job payload to Faktory.
145
161
  # Hash must contain "jid", "jobtype" and "args" elements at minimum.
146
162
  # Returned value will either be the JID String if successful OR
@@ -188,13 +204,11 @@ module Faktory
188
204
  # Return a string signal to process, legal values are "quiet" or "terminate".
189
205
  # The quiet signal is informative: the server won't allow this process to FETCH
190
206
  # any more jobs anyways.
191
- def beat(current_state = nil)
207
+ def beat(current_state = nil, hash)
192
208
  transaction do
193
- if current_state.nil?
194
- command("BEAT", %Q[{"wid":"#{@@random_process_wid}"}])
195
- else
196
- command("BEAT", %Q[{"wid":"#{@@random_process_wid}", "current_state":"#{current_state}"}])
197
- end
209
+ hash["wid"] = @@random_process_wid
210
+ hash["current_state"] = current_state if current_state
211
+ command("BEAT", Faktory.dump_json(hash))
198
212
 
199
213
  str = result!
200
214
  if str == "OK"
@@ -227,6 +241,7 @@ module Faktory
227
241
 
228
242
  def open(timeout = DEFAULT_TIMEOUT)
229
243
  if tls?
244
+ require 'openssl'
230
245
  sock = TCPSocket.new(@location.hostname, @location.port)
231
246
  sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
232
247
 
@@ -248,6 +263,7 @@ module Faktory
248
263
  "hostname": Socket.gethostname,
249
264
  "pid": $$,
250
265
  "labels": Faktory.options[:labels] || ["ruby-#{RUBY_VERSION}"],
266
+ "username": @location.user,
251
267
  "v": 2,
252
268
  }
253
269
 
data/lib/faktory/io.rb CHANGED
@@ -37,9 +37,9 @@ module Faktory
37
37
  loop do
38
38
  result = @sock.read_nonblock(nbytes, exception: false)
39
39
  if result == :wait_readable
40
- raise Faktory::TimeoutError unless @sock.wait_readable(@timeout)
40
+ raise Faktory::TimeoutError unless @sock.to_io.wait_readable(@timeout)
41
41
  elsif result == :wait_writable
42
- raise Faktory::TimeoutError unless @sock.wait_writeable(@timeout)
42
+ raise Faktory::TimeoutError unless @sock.to_io.wait_writeable(@timeout)
43
43
  elsif result == nil
44
44
  raise Errno::ECONNRESET
45
45
  else
data/lib/faktory/job.rb CHANGED
@@ -56,6 +56,11 @@ module Faktory
56
56
  @opts = opts
57
57
  end
58
58
 
59
+ def set(opts)
60
+ @opts = Util.deep_merge(@opts, opts)
61
+ self
62
+ end
63
+
59
64
  def perform_async(*args)
60
65
  client_push(@opts.merge('args'.freeze => args))
61
66
  end
@@ -88,6 +93,11 @@ module Faktory
88
93
  pool = Thread.current[:faktory_via_pool] || item["pool"] || Faktory.server_pool
89
94
  item.delete("pool")
90
95
 
96
+ # the payload hash is shallow copied by `merge` calls BUT we don't deep clone
97
+ # the 'custom' child hash which can be problematic if we mutate it within middleware.
98
+ # Proactively dup it first.
99
+ item["custom"] = item["custom"].dup if item["custom"]
100
+
91
101
  Faktory.client_middleware.invoke(item, pool) do
92
102
  pool.with do |c|
93
103
  c.push(item)
@@ -99,7 +109,7 @@ module Faktory
99
109
  module ClassMethods
100
110
 
101
111
  def set(options)
102
- Setter.new(options.merge!('jobtype'.freeze => self))
112
+ Setter.new(Util.deep_merge(get_faktory_options, options, 'jobtype'.freeze => self))
103
113
  end
104
114
 
105
115
  def perform_async(*args)
@@ -188,5 +198,23 @@ module Faktory
188
198
  end
189
199
 
190
200
  end
201
+
202
+ module Util
203
+ def deep_merge(*hashes)
204
+ initial = hashes.shift.transform_keys(&:to_s)
205
+ hashes.reduce(initial) do |acc, other_hash|
206
+ other_hash.transform_keys!(&:to_s)
207
+ acc.merge(other_hash) do |_key, this_val, other_val|
208
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
209
+ deep_merge(this_val, other_val)
210
+ else
211
+ other_val
212
+ end
213
+ end
214
+ end
215
+ end
216
+ module_function :deep_merge
217
+ end
218
+
191
219
  end
192
220
  end
@@ -60,7 +60,7 @@ module Faktory
60
60
  $0 = PROCTITLES.map {|p| p.call }.join(" ")
61
61
 
62
62
  begin
63
- result = Faktory.server {|c| c.beat(@current_state) }
63
+ result = Faktory.server {|c| c.beat(@current_state, "rss_kb" => memory_usage(::Process.pid)) }
64
64
  case result
65
65
  when "OK"
66
66
  # all good
@@ -78,5 +78,26 @@ module Faktory
78
78
  end
79
79
  end
80
80
 
81
+ MEMORY_GRABBER = case RUBY_PLATFORM
82
+ when /linux/
83
+ ->(pid) {
84
+ IO.readlines("/proc/#{$$}/status").each do |line|
85
+ next unless line.start_with?("VmRSS:")
86
+ break line.split[1].to_i
87
+ end
88
+ }
89
+ when /darwin|bsd/
90
+ ->(pid) {
91
+ `ps -o pid,rss -p #{pid}`.lines.last.split.last.to_i
92
+ }
93
+ else
94
+ ->(pid) { 0 }
95
+ end
96
+
97
+ def memory_usage(pid)
98
+ MEMORY_GRABBER.call(pid)
99
+ end
100
+
101
+
81
102
  end
82
103
  end
@@ -5,7 +5,7 @@
5
5
  module Faktory::Middleware::Batch
6
6
  class Client
7
7
  def call(payload, pool)
8
- b = Thread.current["faktory_batch"]
8
+ b = Thread.current[:faktory_batch]
9
9
  if b
10
10
  payload["custom"] ||= {}
11
11
  payload["custom"]["bid"] = b.bid
@@ -1,5 +1,11 @@
1
1
  require 'faktory/client'
2
2
 
3
+ ##
4
+ #
5
+ # Faktory's MUTATE API allows you to scan the sorted sets
6
+ # within Redis (retries, scheduled, dead) and take action
7
+ # (delete, enqueue, kill) on entries.
8
+ #
3
9
  # require 'faktory/mutate'
4
10
  # cl = Faktory::Client.new
5
11
  # cl.discard(Faktory::RETRIES) do |filter|
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Faktory
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.1"
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: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -94,8 +94,8 @@ executables:
94
94
  extensions: []
95
95
  extra_rdoc_files: []
96
96
  files:
97
+ - ".github/workflows/ci.yml"
97
98
  - ".gitignore"
98
- - ".travis.yml"
99
99
  - Changes.md
100
100
  - Gemfile
101
101
  - Gemfile.lock
@@ -132,7 +132,12 @@ files:
132
132
  homepage: https://github.com/contribsys/faktory_worker_ruby
133
133
  licenses:
134
134
  - LGPL-3.0
135
- metadata: {}
135
+ metadata:
136
+ homepage_uri: https://contribsys.com/faktory
137
+ bug_tracker_uri: https://github.com/contribsys/faktory_worker_ruby/issues
138
+ documentation_uri: https://github.com/contribsys/faktory_worker_ruby/wiki
139
+ changelog_uri: https://github.com/contribsys/faktory_worker_ruby/blob/master/Changes.md
140
+ source_code_uri: https://github.com/contribsys/faktory_worker_ruby
136
141
  post_install_message:
137
142
  rdoc_options: []
138
143
  require_paths:
@@ -148,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
153
  - !ruby/object:Gem::Version
149
154
  version: '0'
150
155
  requirements: []
151
- rubygems_version: 3.2.6
156
+ rubygems_version: 3.1.4
152
157
  signing_key:
153
158
  specification_version: 4
154
159
  summary: Ruby worker for Faktory
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
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