belated 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 535f6d7f0af3565867c6f621fb328966d35ff524e38ffc22813e4410fd66eb2f
4
- data.tar.gz: ace8cc58b9519d07e7bce2f12c5b1e45eba570f75a0a5f34b0496a5acfac679d
3
+ metadata.gz: b76db91c6812b59cfd2ede6c6e8d5664cde8547de40b0d05345f624e9cba4729
4
+ data.tar.gz: 99e886f91004d6d467db2aa7103e59c0da5bedaa5d2359fd9e91bd69b17a424d
5
5
  SHA512:
6
- metadata.gz: '058ed5f47971a9f39d7ec39997f23bdfeb54221b516ee9162330e9a0c783dc9ec6d7633ad029b7d96792e08bd317d5efced10ca2ea97b0e8322507a6e5f9a045'
7
- data.tar.gz: c5ef2e3ad64ecda5e1fa2cb0feab2dda1b50388a523e571fe3be829af76e864973429bb95d0433353dd5a58bf97f2f366d19bd19a7ae0d6d578030646156f542
6
+ metadata.gz: a1c095daefe085f5913c363609a3a5b038a0025e133ed0ab16ad131d09a26c4c4d69489b87e5a4939dd6da105b428f6ea9ab186ef38a53bb2ec3605bdbb8086d
7
+ data.tar.gz: 79532774d5169e6781828792b94ef1dd38c0cedbf68b838b95e2c2d64d01d922e0cb9ac093e76524f3c784f9b346bb0e87bda319fb50e1bb1ac8ecd9abd81fbc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.5] - 2021-08-23
4
+
5
+ - Timezone used inside Belated is all using the server time now, so it's up to the user to take care of that(using `Time.now` instead of `Time.now.utc`)
6
+ - Possible to configure host and port.
7
+ - No need to call `.start` on the client anymore.
8
+ - Logging some error and warn messages now too, instead of it all being info
9
+
3
10
  ## [0.6.4] - 2021-08-22
4
11
  - Inline jobs for testing!
5
12
  ```ruby
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.6.4)
4
+ belated (0.6.5)
5
5
  drb
6
6
  dry-configurable
7
7
  sorted_set
data/README.md CHANGED
@@ -19,9 +19,6 @@ Can be used if you're on a normal instance such as EC2 or Digital Ocean drop. No
19
19
  TODO LIST:
20
20
 
21
21
  - Use GDBM for queue storage? That way could maybe get rid of YAML dumping and make things a bit safer. Not ordered though, so maybe keep a list of the jobs as YAML and update it sometimes? Just as backup. Or RocksDB? Would need to be configurable if you don't have something installed.
22
- - Make DRb port configurable.
23
- - Don't hardcode timezone to UTC.
24
- - Add some checks to the client for proper jobs.
25
22
  - Maybe support ActiveJob?
26
23
  - Have a web UI.
27
24
  - Have a job history
@@ -86,8 +83,6 @@ Then,
86
83
  ```ruby
87
84
  # Get the client
88
85
  client = Belated::Client.instance
89
- # Start the client, only need to do this once
90
- client.start unless client.started?
91
86
  ```
92
87
 
93
88
  and you can use the client!
@@ -137,6 +132,14 @@ Path to Rails project.
137
132
 
138
133
  $ bundle exec belated --workers=10
139
134
 
135
+ Other available settings:
136
+
137
+ $ bundle exec belated --host=1.1.1.1 --port=1234
138
+ # druby://1.1.1.1:1234
139
+ $ bundle exec belated --env
140
+ # environment
141
+
142
+
140
143
  Number of workers.
141
144
 
142
145
  ## Testing
@@ -146,7 +149,6 @@ When testing, you can require `belated/testing` and then call `Belated::Testing.
146
149
  ```ruby
147
150
  `belated/testing`
148
151
  c = Belated::Client.instance
149
- c.start
150
152
  c.perform(proc { 2/ 1}) # Tries to push the job to the drb backend
151
153
  # <Belated::JobWrapper:0x00005654bc2db1f0 @at=nil, @completed=false, @id="95e4dc6a-1876-4adf-ae0f-5ae902f5f024", @job=#<Proc:0x00005654bc2db330 (irb):3>, @max_retries=5, @proc_klass=true, @retries=0>
152
154
  Belated::Testing.inline! # Sidekiq-inspired, now jobs run inline
data/bin/belated CHANGED
@@ -28,9 +28,17 @@ OptionParser.new { |opts|
28
28
  Belated.config.env = env
29
29
  end
30
30
 
31
- opts.on('-c=CONNECT', '--connect=CONNECT', 'Start dRuby connection, default true') do |connect|
31
+ opts.on('-c=CONNECT', '--connect=CONNECT', 'Start dRuby connection, default true, use for testing only') do |connect|
32
32
  Belated.config.connect = connect == 'true'
33
33
  end
34
+
35
+ opts.on('-h=HOST', '--host=HOST', 'dRuby host') do |host|
36
+ Belated.config.host = host
37
+ end
38
+
39
+ opts.on('-p=PORT', '--port=PORT', 'dRuby port') do |port|
40
+ Belated.config.port = port
41
+ end
34
42
  }.parse!
35
43
 
36
44
  instance = Belated.instance
data/lib/belated.rb CHANGED
@@ -22,7 +22,6 @@ class Belated
22
22
  extend Dry::Configurable
23
23
  include Logging
24
24
  include Singleton unless $TESTING
25
- URI = 'druby://localhost:8788'
26
25
  @@queue = Belated::Queue.new
27
26
 
28
27
  setting :rails, true
@@ -32,6 +31,9 @@ class Belated
32
31
  setting :environment, 'development', reader: true
33
32
  setting :logger, Logger.new($stdout), reader: true
34
33
  setting :log_level, :info, reader: true
34
+ setting :host, 'localhost', reader: true
35
+ setting :port, '8788', reader: true
36
+ URI = "druby://#{Belated.host}:#{Belated.port}"
35
37
 
36
38
  # Since it's running as a singleton, we need something to start it up.
37
39
  # Aliased for testing purposes.
@@ -55,7 +57,7 @@ class Belated
55
57
  def connect!
56
58
  DRb.start_service(URI, @@queue, verbose: true)
57
59
  rescue DRb::DRbConnError, Errno::EADDRINUSE
58
- Belated.logger.error 'Could not connect to DRb server.'
60
+ error 'Could not connect to DRb server.'
59
61
  end
60
62
 
61
63
  def trap_signals
@@ -96,12 +98,12 @@ class Belated
96
98
  sleep 5
97
99
  next
98
100
  end
99
- if job.at <= Time.now.utc
101
+ if job.at <= Time.now
100
102
  log "Deleting #{@@queue.future_jobs.delete(job)} from future jobs"
101
103
  @@queue.push(job)
102
104
  end
103
105
  rescue DRb::DRbConnError
104
- log 'DRb connection error!!!!!!'
106
+ error 'DRb connection error!!!!!!'
105
107
  log stats
106
108
  end
107
109
  end
@@ -173,8 +175,6 @@ class Belated
173
175
  def self.job_list
174
176
  @@queue
175
177
  end
176
-
177
- class Error < StandardError; end
178
178
  end
179
179
 
180
180
  require 'belated/rails' if defined?(::Rails::Engine)
@@ -1,4 +1,5 @@
1
1
  require 'belated/job_wrapper'
2
+ require 'belated/exceptions'
2
3
  require 'singleton'
3
4
  class Belated
4
5
  # The client class is responsible for managing the connection to the
@@ -77,8 +78,8 @@ class Belated
77
78
  # @param max_retries [Integer] - Times the job should be retried if it fails.
78
79
  # @return [JobWrapper] - The job wrapper for the queue.
79
80
  def perform(job, at: nil, max_retries: 5)
80
- log 'Call .start on the client instance first!' unless started?
81
-
81
+ start unless started?
82
+ check_if_proper_job!(job)
82
83
  job_wrapper = wrap_job(job, at: at, max_retries: max_retries)
83
84
  bank.push(job_wrapper)
84
85
  @mutex.synchronize do
@@ -92,6 +93,12 @@ class Belated
92
93
 
93
94
  private
94
95
 
96
+ def check_if_proper_job!(job)
97
+ return if job.respond_to?(:call) || job.respond_to?(:perform)
98
+
99
+ raise JobError, 'job does not implement .call nor .perform!'
100
+ end
101
+
95
102
  def wrap_job(job, at:, max_retries:)
96
103
  return job if job.is_a?(JobWrapper)
97
104
 
@@ -0,0 +1,3 @@
1
+ class Belated
2
+ class JobError < StandardError; end
3
+ end
@@ -53,7 +53,7 @@ class Belated
53
53
  self.retries += 1
54
54
  return if retries > max_retries
55
55
 
56
- self.at = Time.now.utc + (retries.next**4)
56
+ self.at = Time.now + (retries.next**4)
57
57
  log "Job #{id} failed, retrying at #{at}"
58
58
  Belated.job_list.push(self)
59
59
  end
@@ -12,6 +12,14 @@ class Belated
12
12
  logger.__send__(Belated.log_level, message)
13
13
  end
14
14
 
15
+ def warn(message)
16
+ logger.warn(message)
17
+ end
18
+
19
+ def error(message)
20
+ logger.error(message)
21
+ end
22
+
15
23
  def logger=(logger)
16
24
  @logger = logger
17
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.6.4'
4
+ VERSION = '0.6.5'
5
5
  end
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.6.4
4
+ version: 0.6.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-22 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: drb
@@ -94,6 +94,7 @@ files:
94
94
  - bin/setup
95
95
  - lib/belated.rb
96
96
  - lib/belated/client.rb
97
+ - lib/belated/exceptions.rb
97
98
  - lib/belated/job.rb
98
99
  - lib/belated/job_wrapper.rb
99
100
  - lib/belated/logging.rb