belated 0.4.1 → 0.4.2

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: ed06672798a42b07c69c9dc84f32d1ba12a58a7b95028f0c4a2f5d1a5f0b04c4
4
- data.tar.gz: 0ecf13b8abf076c5fbe8a0037017840e55f32c674f4a40092a6e35845503f4e9
3
+ metadata.gz: 33b9abbd449108f850f65e0afaa92929c780b03856e9e151efb6cc33b84021d5
4
+ data.tar.gz: eb9a7142602bae2572454c227d057adf9f38397c1638dcc6f66f2cd16019b766
5
5
  SHA512:
6
- metadata.gz: 1e16e639db3c05d9112a4b31232d0cb78dbe6fe93ed05cd33f1d9a7856ded7c40319c145c20cddf1dd5a8bafb2894d8f96d46fc423a6718180e4d5e4584fdc41
7
- data.tar.gz: 86793a533285a0ae5761b3eb11d4f16fe44793cc83d2a24c6f7aebae6a4d27ff7795b3ef2e69ce7e2b12f5c86fb9e108d5252f2aa863c645262f880f0ad56cf7
6
+ metadata.gz: c50c1dfe80dceee431785ec150a0a5b6a7c220e18fc8c6a05069637d474d848719c5bfd05f0c0f4125e379348296ebb92823e71b985e76cccffe9e3080349822
7
+ data.tar.gz: 357053481de792ea44b832eade91895d5257074e3381333ddb58aaa48c20d08b6d02d6e84b57664218108ae2927d8247db7229f1a1fa91483a745a3202031a0d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.2] - 2021-08-05
4
+
5
+ - Client also handles no connection, now it saves jobs to a bank and adds them to the queue once it has a connection.
3
6
  ## [0.4.1] - 2021-08-05
4
7
 
5
8
  - Now handles saving future jobs too! So if you have a job enqueued for tomorrow, and restart Belated, it should still be enqueued.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.4.1)
4
+ belated (0.4.2)
5
5
  drb
6
6
  dry-configurable
7
7
 
data/README.md CHANGED
@@ -12,24 +12,16 @@ Can be used with or without Rails.
12
12
 
13
13
  TODO LIST:
14
14
 
15
- - Catch SIGTERM and friends
16
- - Now supports it, partly.
15
+ - Add some checks to the client for proper jobs.
17
16
  - Don't crash on errors (Partially done)
18
17
  - Have multiple queues?
19
18
  - Maybe support ActiveJob?
20
19
  - Have a web UI
21
20
  - Do some performance testing
21
+ - Deploy a Rails app to production that is using Belated
22
+ and mention it in the readme.
22
23
  - Add a section telling people to use Sidekiq if they can
23
24
 
24
- DONE
25
-
26
- - ~~Make it possible to schedule jobs~~
27
- - ~~Marshal the job queue into a file so you don't lose all progress~~
28
- (Ended up using YAML)
29
- - ~~Add a logger~~
30
- - ~~Support Rails~~ (Supported!)
31
- - ~~Parse options from command line, eg. `--workers 10`~~(Done!)
32
-
33
25
  ## Installation
34
26
 
35
27
  Add this line to your application's Gemfile:
@@ -1,12 +1,12 @@
1
1
  class Belated
2
2
  # The client class is responsible for managing the connection to the
3
- # DRb server.
3
+ # DRb server. If it has no connection, it adds the jobs to a bank queue.
4
4
  # You can enqueue jobs to be processed by the server.
5
5
  # Example:
6
6
  # client = Belated::Client.new
7
7
  # client.enqueue(JubJub.new, at: Time.now + 5.seconds)
8
8
  class Client
9
- attr_accessor :queue
9
+ attr_accessor :queue, :bank, :banker_thread
10
10
 
11
11
  # Starts up the client.
12
12
  # Connects to the queue through DRb.
@@ -15,15 +15,27 @@ class Belated
15
15
  server_uri = Belated::URI
16
16
  # @bank =
17
17
  DRb.start_service
18
+ self.bank = Thread::Queue.new
18
19
  self.queue = DRbObject.new_with_uri(server_uri)
20
+ self.banker_thread = Thread.new do
21
+ loop do
22
+ sleep 0.05
23
+ next unless (job, at = bank.pop)
24
+
25
+ perform(job, at: at)
26
+ end
27
+ end
19
28
  end
20
29
 
21
30
  # The method that pushes the jobs to the queue.
31
+ # If there is no connection, it pushes the job to the bank.
22
32
  # @param job [Object] - The the job to be pushed.
23
33
  # @param at [Date] - The time at which the job should be executed.
24
34
  # @return [Object] - The job that was pushed.
25
35
  def perform(job, at: nil)
26
36
  queue.push(job, at: at)
37
+ rescue DRb::DRbConnError
38
+ bank.push([job, at])
27
39
  end
28
40
  alias perform_belated perform
29
41
  alias perform_later perform
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen