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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -11
- data/lib/belated/client.rb +14 -2
- data/lib/belated/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33b9abbd449108f850f65e0afaa92929c780b03856e9e151efb6cc33b84021d5
|
|
4
|
+
data.tar.gz: eb9a7142602bae2572454c227d057adf9f38397c1638dcc6f66f2cd16019b766
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/README.md
CHANGED
|
@@ -12,24 +12,16 @@ Can be used with or without Rails.
|
|
|
12
12
|
|
|
13
13
|
TODO LIST:
|
|
14
14
|
|
|
15
|
-
-
|
|
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:
|
data/lib/belated/client.rb
CHANGED
|
@@ -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
|
data/lib/belated/version.rb
CHANGED