belated 0.5.1 → 0.5.5

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: 5824acbe80af6b8b64a09ab2a0ee62d204504f99edee65d426ab05c737d52da0
4
- data.tar.gz: ed3ff585ac66e715e55afd143bcf63fa534bd3434c9f6e9b5d4e0960fa47d9c8
3
+ metadata.gz: 94a7f0ce2c6f7c80dfe5b8410c72dac95dbc709937361b36aa7eaeea091d8cfb
4
+ data.tar.gz: da41ab683e0a2729b1dc1e7228592e91a0d259cc46bbaf6ef4a2186abb379330
5
5
  SHA512:
6
- metadata.gz: 7d42b2530bd69a3a523383d98ccceb7ef76406bcf4c20791d93231b31004a6c43a208781308ede75fb614c84281bac3a97394646df9f0225a09de244030ff485
7
- data.tar.gz: 62a9d873677daba7273ba182c2c0470f9ef9188d8a370d35fa94a7a45676abdbb4a26898299b886e06496f5bab85e9f740276e62f9dd9ee507f8ceb891605080
6
+ metadata.gz: cacbed28173905bf3fd5489bb8797abecfe4402096cea5d068dcec5a3bf27d9d5c1d048c7d9cc159aedef9cda981a038f4177d6ccd3648c87752d2bedb94390d
7
+ data.tar.gz: f92f505a4d8a53c13b4411ae611d5584377f09b31f8e33f9f39a1daf77b3684b977e3c01a472a654c4c07251a1e0aba6fc2f9953eb7383ef1c15fd7be2385e33
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
+ require: rubocop-performance
1
2
  AllCops:
2
3
  TargetRubyVersion: 2.7
3
4
  NewCops: enable
@@ -22,9 +23,6 @@ Style/AsciiComments:
22
23
  Style/ClassVars:
23
24
  Enabled: false
24
25
 
25
- Style/Documentation:
26
- Enabled: false
27
-
28
26
  Style/GlobalVars:
29
27
  Enabled: false
30
28
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.5] - 2021-08-15
4
+
5
+ - Use SortedSet for future jobs, to avoid having to go through the whole list every few seconds.
6
+
7
+
8
+ ## [0.5.4] - 2021-08-13
9
+
10
+ - Client was using 100% CPU when it had no connection. (on $5 Digital Ocean droplet) Should be fixed now.
11
+
12
+ ## [0.5.3] - 2021-08-13
13
+
14
+ - A bit less looping - better performance.
15
+ ## [0.5.2] - 2021-08-13
16
+
17
+ - An error with shutdown handling was fixed.
18
+
3
19
  ## [0.5.1] - 2021-08-12
4
20
 
5
21
  - Requiring byebug in bin file. 😮
data/Gemfile CHANGED
@@ -9,10 +9,10 @@ gem 'rake', '~> 13.0'
9
9
 
10
10
  gem 'rspec', '~> 3.0'
11
11
 
12
- gem 'rubocop', '~> 1.7'
13
-
14
12
  gem 'database_cleaner-active_record'
15
13
  gem 'rails', '>= 6.1.3'
16
14
  gem 'rspec-rails'
15
+ gem 'rubocop', '~> 1.7'
16
+ gem 'rubocop-performance', require: false
17
17
  gem 'sqlite3'
18
18
  gem 'stackprof'
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.5.1)
4
+ belated (0.5.5)
5
5
  drb
6
6
  dry-configurable
7
+ sorted_set
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -135,6 +136,7 @@ GEM
135
136
  thor (~> 1.0)
136
137
  rainbow (3.0.0)
137
138
  rake (13.0.6)
139
+ rbtree (0.4.4)
138
140
  regexp_parser (2.1.1)
139
141
  rexml (3.2.5)
140
142
  rspec (3.10.0)
@@ -169,7 +171,14 @@ GEM
169
171
  unicode-display_width (>= 1.4.0, < 3.0)
170
172
  rubocop-ast (1.7.0)
171
173
  parser (>= 3.0.1.1)
174
+ rubocop-performance (1.11.4)
175
+ rubocop (>= 1.7.0, < 2.0)
176
+ rubocop-ast (>= 0.4.0)
172
177
  ruby-progressbar (1.11.0)
178
+ set (1.0.1)
179
+ sorted_set (1.0.3)
180
+ rbtree
181
+ set (~> 1.0)
173
182
  sprockets (4.0.2)
174
183
  concurrent-ruby (~> 1.0)
175
184
  rack (> 1, < 3)
@@ -200,8 +209,9 @@ DEPENDENCIES
200
209
  rspec (~> 3.0)
201
210
  rspec-rails
202
211
  rubocop (~> 1.7)
212
+ rubocop-performance
203
213
  sqlite3
204
214
  stackprof
205
215
 
206
216
  BUNDLED WITH
207
- 2.2.17
217
+ 2.2.22
data/README.md CHANGED
@@ -16,8 +16,10 @@ Can be used with or without Rails.
16
16
 
17
17
  TODO LIST:
18
18
 
19
+ - Use GDBM for queeue storage? That way could maybe get rid of YAML dumping and make things a bit safer.
20
+ - Rescue `DRb::DRbRemoteError` when shutting down, might not need to if using GDBM?
19
21
  - Don't use class instance variables.
20
- - Make port configurable.
22
+ - Make DRb port configurable.
21
23
  - Don't hardcode timezone.
22
24
  - Add some checks to the client for proper jobs.
23
25
  - Have multiple queues?
@@ -27,6 +29,7 @@ TODO LIST:
27
29
  - Do some performance testing.
28
30
  - Deploy a Rails app to production that is using Belated
29
31
  and mention it in the readme. (Capistrano support?)
32
+ ([Wasurechatta](wasurechatta.com))
30
33
  - Add a section telling people to use Sidekiq if they can
31
34
 
32
35
  ## Installation
@@ -136,9 +139,15 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
136
139
 
137
140
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
138
141
 
142
+
143
+ # Possible problems
144
+
145
+ If you have the port 8788 already in use, you can check the ports in use in Linux with the following command:
146
+
147
+ $ sudo lsof -i -P -n | grep LISTEN
139
148
  ## Contributing
140
149
 
141
- Bug reports and pull requests are welcome on GitHub at https://github.com/sampokuokkanen/belated. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sampokuokkanen/belated/blob/master/CODE_OF_CONDUCT.md).
150
+ Bug reports, questions and pull requests are welcome on GitHub at https://github.com/sampokuokkanen/belated. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sampokuokkanen/belated/blob/master/CODE_OF_CONDUCT.md).
142
151
 
143
152
  ## License
144
153
 
data/belated.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  # Uncomment to register a new dependency of your gem
34
34
  spec.add_dependency 'drb'
35
35
  spec.add_dependency 'dry-configurable'
36
+ spec.add_dependency 'sorted_set'
36
37
  spec.add_development_dependency 'byebug'
37
38
 
38
39
  # For more information and examples about making a new gem, checkout our
data/lib/belated.rb CHANGED
@@ -91,13 +91,17 @@ class Belated
91
91
  def enqueue_future_jobs
92
92
  log 'starting future jobs thread'
93
93
  loop do
94
- @@queue.future_jobs.each_with_index do |job, i|
95
- if job.at <= Time.now.utc
96
- log "Deleting #{@@queue.future_jobs.delete_at(i)} from future jobs"
97
- @@queue.push(job)
98
- end
94
+ sleep 0.1
95
+ job = @@queue.future_jobs.at(0)
96
+ if job.nil?
97
+ sleep 5
98
+ next
99
+ end
100
+
101
+ if job.at <= Time.now.utc
102
+ log "Deleting #{@@queue.future_jobs.delete(job)} from future jobs"
103
+ @@queue.push(job)
99
104
  end
100
- sleep 0.01
101
105
  end
102
106
  end
103
107
 
@@ -26,6 +26,12 @@ class Belated
26
26
  def start_banker_thread
27
27
  self.banker_thread = Thread.new do
28
28
  loop do
29
+ sleep 0.01
30
+ unless drb_connected?
31
+ sleep(10)
32
+ next
33
+ end
34
+
29
35
  job = bank.pop
30
36
 
31
37
  perform(job)
@@ -50,9 +56,16 @@ class Belated
50
56
  rescue DRb::DRbConnError
51
57
  bank.push(job_wrapper)
52
58
  start_banker_thread if banker_thread.nil?
53
- banker_thread.wakeup if banker_thread.status == 'sleep'
54
59
  end
55
60
  alias perform_belated perform
56
61
  alias perform_later perform
62
+
63
+ private
64
+
65
+ def drb_connected?
66
+ queue.connected?
67
+ rescue StandardError
68
+ false
69
+ end
57
70
  end
58
71
  end
@@ -3,6 +3,7 @@ require_relative 'logging'
3
3
 
4
4
  class Belated
5
5
  class JobWrapper
6
+ include Comparable
6
7
  include Logging
7
8
  attr_accessor :retries, :max_retries, :id, :job, :at
8
9
 
@@ -14,6 +15,10 @@ class Belated
14
15
  self.at = at
15
16
  end
16
17
 
18
+ def <=>(another)
19
+ at <=> another.at
20
+ end
21
+
17
22
  # rubocop:disable Lint/RescueException
18
23
  def perform
19
24
  if job.respond_to?(:call)
data/lib/belated/queue.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'belated/job'
4
4
  require 'belated/logging'
5
5
  require 'belated/job_wrapper'
6
+ require 'sorted_set'
7
+
6
8
  class Belated
7
9
  class Queue
8
10
  include Logging
@@ -10,13 +12,14 @@ class Belated
10
12
 
11
13
  FILE_NAME = 'belated_dump'
12
14
 
13
- def initialize(queue: Thread::Queue.new, future_jobs: [])
15
+ def initialize(queue: Thread::Queue.new, future_jobs: SortedSet.new)
14
16
  @queue = queue
15
17
  self.future_jobs = future_jobs
16
18
  end
17
19
 
18
20
  def push(job)
19
- if job.at.nil? || job.at <= Time.now.utc
21
+ if job.is_a?(Symbol) || job.at.nil? ||
22
+ job.at <= Time.now.utc
20
23
  @queue.push(job)
21
24
  else
22
25
  @future_jobs << job
@@ -71,10 +74,14 @@ class Belated
71
74
  pp File.open(FILE_NAME, 'wb') { |f| f.write(YAML.dump(class_array)) }
72
75
  end
73
76
 
77
+ def connected?
78
+ true
79
+ end
80
+
74
81
  private
75
82
 
76
83
  def proc_or_shutdown?(job)
77
- job.job.instance_of?(Proc) || job == :shutdown
84
+ job.job.instance_of?(Proc) || job.is_a?(Symbol)
78
85
  end
79
86
  end
80
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.5'
5
5
  end
@@ -16,7 +16,7 @@ class Belated
16
16
  log "Worker #{@number} fetching jobs!"
17
17
  next unless (job = Belated.fetch_job)
18
18
 
19
- break if job == :shutdown
19
+ break if job.is_a?(Symbol)
20
20
 
21
21
  log "Worker #{@number} got job: #{job.inspect}"
22
22
  job.perform
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2021-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: drb
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sorted_set
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: byebug
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  requirements: []
112
- rubygems_version: 3.2.15
126
+ rubygems_version: 3.2.22
113
127
  signing_key:
114
128
  specification_version: 4
115
129
  summary: Run background jobs with Belated and dRuby!