belated 0.4.2 → 0.4.3

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: 33b9abbd449108f850f65e0afaa92929c780b03856e9e151efb6cc33b84021d5
4
- data.tar.gz: eb9a7142602bae2572454c227d057adf9f38397c1638dcc6f66f2cd16019b766
3
+ metadata.gz: 598cfda479ae3ec79564557a4f111ff5600c255bdf3cc8b3e03194b0b0b6ce86
4
+ data.tar.gz: f6b07150c218bf9754f5d40625e7e5d26673f87bf4d8a1baa4ef87814edbbc09
5
5
  SHA512:
6
- metadata.gz: c50c1dfe80dceee431785ec150a0a5b6a7c220e18fc8c6a05069637d474d848719c5bfd05f0c0f4125e379348296ebb92823e71b985e76cccffe9e3080349822
7
- data.tar.gz: 357053481de792ea44b832eade91895d5257074e3381333ddb58aaa48c20d08b6d02d6e84b57664218108ae2927d8247db7229f1a1fa91483a745a3202031a0d
6
+ metadata.gz: 43ab001fcc721b6750ec2c7d3ee00f32ab58ff9909268bb9dda92d7096a5cca85782fbd8f3502295cc07086ac6ef18c056124f55ef4a706b607d2aab3c667ef8
7
+ data.tar.gz: c83cec5063743c8ed84a28a1b5995b7b3d7deeade1f6f352d81d1dca5b1531231dc46678f14e1ad6795662d8105dfc957ca81f7868996b310bc8b4128132e0c9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.3] - 2021-08-06
4
+
5
+ - Client now starts the banker thread to execute jobs that were enqueued when there was no connection to Belated only if necessary.
3
6
  ## [0.4.2] - 2021-08-05
4
7
 
5
8
  - Client also handles no connection, now it saves jobs to a bank and adds them to the queue once it has a connection.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.4.2)
4
+ belated (0.4.3)
5
5
  drb
6
6
  dry-configurable
7
7
 
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  This is Belated, a new Ruby backend job library! It supports running procs and classes in the background. To deal with restarts, it uses YAML to load the queue into a file, which it then calls at startup to find the previous jobs.
6
6
 
7
+ Belated uses the Ruby Queue class, so it's First In, First Out (FIFO).
8
+
7
9
  Note that Belated used to be called HardWorker. That name was already in use in Sidekiq documentation and a bit too generic anyway.
8
10
 
9
11
  It uses dRuby to do the communication! Which is absolute great. No need for Redis or PostgreSQL, just Ruby standard libraries.
@@ -99,6 +101,8 @@ If you don't want the job to run right away, you can also pass it a keyword para
99
101
  client.perform_belated(job, Time.now + 1.month)
100
102
  ```
101
103
 
104
+ Note that you probably want to memoize the client, as it always creates a 'banker thread' now if you have no connection. Maybe even use it as a global!(`$client`)
105
+
102
106
  # Settings
103
107
 
104
108
  Configuring Belated:
@@ -13,14 +13,19 @@ class Belated
13
13
  # @return [void]
14
14
  def initialize
15
15
  server_uri = Belated::URI
16
- # @bank =
17
16
  DRb.start_service
18
17
  self.bank = Thread::Queue.new
19
18
  self.queue = DRbObject.new_with_uri(server_uri)
19
+ end
20
+
21
+ # Thread in charge of handling the bank queue.
22
+ # You probably want to memoize the client in order to avoid
23
+ # having many threads in the sleep state.
24
+ # @return [void]
25
+ def start_banker_thread
20
26
  self.banker_thread = Thread.new do
21
27
  loop do
22
- sleep 0.05
23
- next unless (job, at = bank.pop)
28
+ job, at = bank.pop
24
29
 
25
30
  perform(job, at: at)
26
31
  end
@@ -36,6 +41,8 @@ class Belated
36
41
  queue.push(job, at: at)
37
42
  rescue DRb::DRbConnError
38
43
  bank.push([job, at])
44
+ start_banker_thread if banker_thread.nil?
45
+ # banker_thread.wakeup if banker_thread.status == 'sleep'
39
46
  end
40
47
  alias perform_belated perform
41
48
  alias perform_later perform
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
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.4.2
4
+ version: 0.4.3
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-05 00:00:00.000000000 Z
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: drb