belated 0.8.0 → 0.9.0

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: 9bd1b76847288931abea65941cf12792557ce92d930f07132d3d78f40cd736e0
4
- data.tar.gz: 264e80282918062e70948fcc6f9357b56e49170eabab1c963ecf6ab4767401a2
3
+ metadata.gz: 67777540e4d30c80208702f5724fa0e1d1cd37fcfb454b5f631f97892f6c1a47
4
+ data.tar.gz: 811689e8a3a180b03a42885c90441aaaada3786b23f6bc4379c78b5376da0072
5
5
  SHA512:
6
- metadata.gz: 5f96e1e24d51fea623952ac7d0dba6333bd7f2ec114fe271a7dc56a37b768f3bad58f0bcec1323038d0cf1fd0cb5104a0e66e93757ad7e9d4efe579596c95fac
7
- data.tar.gz: ceab192601a13e0e8413f6205e5d82e1ebca1a483f4201cabeda670f8f18d0cf7225fc1442eec96474d7cafc561e4c4808e14ebbffae436b144a3d4805f2770f
6
+ metadata.gz: a02df25ac3e60f1bce4d470aceccc6208c4abe938e5b051f0ace46dc86569b316bdc13230d51a4008c36927bdcf4c57dbb843200ea8f2e2575d8570bcfca4251
7
+ data.tar.gz: 5ac24e84ed38c3728b5f589deb66a16722b5c3e73da3c61e83803c0574c16e8b42da99bd8148b19bd1a316765de9b552967082fa53d3ac63c1c285e3263a1a69
data/.gitignore CHANGED
@@ -11,7 +11,8 @@
11
11
  .rspec_status
12
12
  .byebug_history
13
13
  /dummy/tmp/cache/
14
- /dummy/log/
15
- /dummy/log/test.log
14
+ /dummy/log/*.log
15
+ /dummy/db
16
16
  belated_dump
17
17
  stackprof*
18
+ history_*
data/.rspec CHANGED
@@ -1,4 +1,5 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
- --profile
4
+ --profile
5
+ --fail-fast
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0] - 2021-11-03
4
+ - Fix env setting bug. If you set env, it was not working... now it should work.
5
+ - Add rudimentary admin panel. You can see future jobs from there.
6
+ ## [0.8.3] - 2021-09-10
7
+ - Add environment to the names of the pstore files. This way you won't get your development, staging, and production jobs mixed up. (I was getting my test and dev jobs mixed up)
8
+
9
+ ## [0.8.2] - 2021-09-09
10
+ - Fixed a bug where the adapter was not defined when loading jobs from the PStore file.
11
+
12
+ ## [0.8.1] - 2021-09-09
13
+ - Now you can delete jobs from the future jobs queue. This is useful if you want to delete a job that is scheduled for a future date.
14
+
3
15
  ## [0.8] - 2021-09-08
4
16
  - Using PStore for future jobs backup and job history. Job history is rotated daily, future jobs cannot at the moment.
5
17
  - PStore has ultrasafe mode, should test whether that makes things very slow. If not, might be worth using it for the peace of mind. Or at least have it as an option.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.8.0)
4
+ belated (0.9.0)
5
5
  drb
6
6
  dry-configurable
7
7
  pstore
@@ -11,60 +11,60 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actioncable (6.1.4)
15
- actionpack (= 6.1.4)
16
- activesupport (= 6.1.4)
14
+ actioncable (6.1.4.1)
15
+ actionpack (= 6.1.4.1)
16
+ activesupport (= 6.1.4.1)
17
17
  nio4r (~> 2.0)
18
18
  websocket-driver (>= 0.6.1)
19
- actionmailbox (6.1.4)
20
- actionpack (= 6.1.4)
21
- activejob (= 6.1.4)
22
- activerecord (= 6.1.4)
23
- activestorage (= 6.1.4)
24
- activesupport (= 6.1.4)
19
+ actionmailbox (6.1.4.1)
20
+ actionpack (= 6.1.4.1)
21
+ activejob (= 6.1.4.1)
22
+ activerecord (= 6.1.4.1)
23
+ activestorage (= 6.1.4.1)
24
+ activesupport (= 6.1.4.1)
25
25
  mail (>= 2.7.1)
26
- actionmailer (6.1.4)
27
- actionpack (= 6.1.4)
28
- actionview (= 6.1.4)
29
- activejob (= 6.1.4)
30
- activesupport (= 6.1.4)
26
+ actionmailer (6.1.4.1)
27
+ actionpack (= 6.1.4.1)
28
+ actionview (= 6.1.4.1)
29
+ activejob (= 6.1.4.1)
30
+ activesupport (= 6.1.4.1)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  rails-dom-testing (~> 2.0)
33
- actionpack (6.1.4)
34
- actionview (= 6.1.4)
35
- activesupport (= 6.1.4)
33
+ actionpack (6.1.4.1)
34
+ actionview (= 6.1.4.1)
35
+ activesupport (= 6.1.4.1)
36
36
  rack (~> 2.0, >= 2.0.9)
37
37
  rack-test (>= 0.6.3)
38
38
  rails-dom-testing (~> 2.0)
39
39
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
- actiontext (6.1.4)
41
- actionpack (= 6.1.4)
42
- activerecord (= 6.1.4)
43
- activestorage (= 6.1.4)
44
- activesupport (= 6.1.4)
40
+ actiontext (6.1.4.1)
41
+ actionpack (= 6.1.4.1)
42
+ activerecord (= 6.1.4.1)
43
+ activestorage (= 6.1.4.1)
44
+ activesupport (= 6.1.4.1)
45
45
  nokogiri (>= 1.8.5)
46
- actionview (6.1.4)
47
- activesupport (= 6.1.4)
46
+ actionview (6.1.4.1)
47
+ activesupport (= 6.1.4.1)
48
48
  builder (~> 3.1)
49
49
  erubi (~> 1.4)
50
50
  rails-dom-testing (~> 2.0)
51
51
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
- activejob (6.1.4)
53
- activesupport (= 6.1.4)
52
+ activejob (6.1.4.1)
53
+ activesupport (= 6.1.4.1)
54
54
  globalid (>= 0.3.6)
55
- activemodel (6.1.4)
56
- activesupport (= 6.1.4)
57
- activerecord (6.1.4)
58
- activemodel (= 6.1.4)
59
- activesupport (= 6.1.4)
60
- activestorage (6.1.4)
61
- actionpack (= 6.1.4)
62
- activejob (= 6.1.4)
63
- activerecord (= 6.1.4)
64
- activesupport (= 6.1.4)
55
+ activemodel (6.1.4.1)
56
+ activesupport (= 6.1.4.1)
57
+ activerecord (6.1.4.1)
58
+ activemodel (= 6.1.4.1)
59
+ activesupport (= 6.1.4.1)
60
+ activestorage (6.1.4.1)
61
+ actionpack (= 6.1.4.1)
62
+ activejob (= 6.1.4.1)
63
+ activerecord (= 6.1.4.1)
64
+ activesupport (= 6.1.4.1)
65
65
  marcel (~> 1.0.0)
66
66
  mini_mime (>= 1.1.0)
67
- activesupport (6.1.4)
67
+ activesupport (6.1.4.1)
68
68
  concurrent-ruby (~> 1.0, >= 1.0.2)
69
69
  i18n (>= 1.6, < 2)
70
70
  minitest (>= 5.1)
@@ -80,66 +80,67 @@ GEM
80
80
  database_cleaner-core (~> 2.0.0)
81
81
  database_cleaner-core (2.0.1)
82
82
  diff-lcs (1.4.4)
83
- drb (2.0.4)
84
- dry-configurable (0.12.1)
83
+ drb (2.1.0)
84
+ ruby2_keywords
85
+ dry-configurable (0.13.0)
85
86
  concurrent-ruby (~> 1.0)
86
- dry-core (~> 0.5, >= 0.5.0)
87
+ dry-core (~> 0.6)
87
88
  dry-core (0.7.1)
88
89
  concurrent-ruby (~> 1.0)
89
90
  erubi (1.10.0)
90
- globalid (0.4.2)
91
- activesupport (>= 4.2.0)
91
+ globalid (0.5.2)
92
+ activesupport (>= 5.0)
92
93
  i18n (1.8.10)
93
94
  concurrent-ruby (~> 1.0)
94
- loofah (2.10.0)
95
+ loofah (2.12.0)
95
96
  crass (~> 1.0.2)
96
97
  nokogiri (>= 1.5.9)
97
98
  mail (2.7.1)
98
99
  mini_mime (>= 0.1.1)
99
- marcel (1.0.1)
100
+ marcel (1.0.2)
100
101
  method_source (1.0.0)
101
- mini_mime (1.1.0)
102
+ mini_mime (1.1.2)
102
103
  mini_portile2 (2.6.1)
103
104
  minitest (5.14.4)
104
- nio4r (2.5.7)
105
- nokogiri (1.12.3)
105
+ nio4r (2.5.8)
106
+ nokogiri (1.12.5)
106
107
  mini_portile2 (~> 2.6.1)
107
108
  racc (~> 1.4)
108
- nokogiri (1.12.3-x86_64-darwin)
109
+ nokogiri (1.12.5-x86_64-darwin)
109
110
  racc (~> 1.4)
110
- nokogiri (1.12.3-x86_64-linux)
111
+ nokogiri (1.12.5-x86_64-linux)
111
112
  racc (~> 1.4)
112
- parallel (1.20.1)
113
+ parallel (1.21.0)
113
114
  parser (3.0.2.0)
114
115
  ast (~> 2.4.1)
115
116
  pstore (0.1.1)
116
- racc (1.5.2)
117
+ racc (1.6.0)
117
118
  rack (2.2.3)
118
119
  rack-test (1.1.0)
119
120
  rack (>= 1.0, < 3)
120
- rails (6.1.4)
121
- actioncable (= 6.1.4)
122
- actionmailbox (= 6.1.4)
123
- actionmailer (= 6.1.4)
124
- actionpack (= 6.1.4)
125
- actiontext (= 6.1.4)
126
- actionview (= 6.1.4)
127
- activejob (= 6.1.4)
128
- activemodel (= 6.1.4)
129
- activerecord (= 6.1.4)
130
- activestorage (= 6.1.4)
131
- activesupport (= 6.1.4)
121
+ rails (6.1.4.1)
122
+ actioncable (= 6.1.4.1)
123
+ actionmailbox (= 6.1.4.1)
124
+ actionmailer (= 6.1.4.1)
125
+ actionpack (= 6.1.4.1)
126
+ actiontext (= 6.1.4.1)
127
+ actionview (= 6.1.4.1)
128
+ activejob (= 6.1.4.1)
129
+ activemodel (= 6.1.4.1)
130
+ activerecord (= 6.1.4.1)
131
+ activestorage (= 6.1.4.1)
132
+ activesupport (= 6.1.4.1)
132
133
  bundler (>= 1.15.0)
133
- railties (= 6.1.4)
134
+ railties (= 6.1.4.1)
134
135
  sprockets-rails (>= 2.0.0)
135
136
  rails-dom-testing (2.0.3)
136
137
  activesupport (>= 4.2.0)
137
138
  nokogiri (>= 1.6)
138
- rails-html-sanitizer (1.3.0)
139
+ rails-html-sanitizer (1.4.2)
139
140
  loofah (~> 2.3)
140
- railties (6.1.4)
141
- actionpack (= 6.1.4)
142
- activesupport (= 6.1.4)
141
+ railties (6.1.4.1)
142
+ actionpack (= 6.1.4.1)
143
+ activesupport (= 6.1.4.1)
143
144
  method_source
144
145
  rake (>= 0.13)
145
146
  thor (~> 1.0)
@@ -160,7 +161,7 @@ GEM
160
161
  rspec-mocks (3.10.2)
161
162
  diff-lcs (>= 1.2.0, < 2.0)
162
163
  rspec-support (~> 3.10.0)
163
- rspec-rails (5.0.1)
164
+ rspec-rails (5.0.2)
164
165
  actionpack (>= 5.2)
165
166
  activesupport (>= 5.2)
166
167
  railties (>= 5.2)
@@ -169,26 +170,25 @@ GEM
169
170
  rspec-mocks (~> 3.10)
170
171
  rspec-support (~> 3.10)
171
172
  rspec-support (3.10.2)
172
- rubocop (1.19.0)
173
+ rubocop (1.22.3)
173
174
  parallel (~> 1.10)
174
175
  parser (>= 3.0.0.0)
175
176
  rainbow (>= 2.2.2, < 4.0)
176
177
  regexp_parser (>= 1.8, < 3.0)
177
178
  rexml
178
- rubocop-ast (>= 1.9.1, < 2.0)
179
+ rubocop-ast (>= 1.12.0, < 2.0)
179
180
  ruby-progressbar (~> 1.7)
180
181
  unicode-display_width (>= 1.4.0, < 3.0)
181
- rubocop-ast (1.10.0)
182
+ rubocop-ast (1.12.0)
182
183
  parser (>= 3.0.1.1)
183
184
  rubocop-discourse (2.4.2)
184
185
  rubocop (>= 1.1.0)
185
186
  rubocop-rspec (>= 2.0.0)
186
- rubocop-rspec (2.4.0)
187
- rubocop (~> 1.0)
188
- rubocop-ast (>= 1.1.0)
187
+ rubocop-rspec (2.5.0)
188
+ rubocop (~> 1.19)
189
189
  ruby-progressbar (1.11.0)
190
190
  ruby2_keywords (0.0.5)
191
- set (1.0.1)
191
+ set (1.0.2)
192
192
  sorted_set (1.0.3)
193
193
  rbtree
194
194
  set (~> 1.0)
@@ -203,11 +203,11 @@ GEM
203
203
  thor (1.1.0)
204
204
  tzinfo (2.0.4)
205
205
  concurrent-ruby (~> 1.0)
206
- unicode-display_width (2.0.0)
206
+ unicode-display_width (2.1.0)
207
207
  websocket-driver (0.7.5)
208
208
  websocket-extensions (>= 0.1.0)
209
209
  websocket-extensions (0.1.5)
210
- zeitwerk (2.4.2)
210
+ zeitwerk (2.5.1)
211
211
 
212
212
  PLATFORMS
213
213
  ruby
data/README.md CHANGED
@@ -74,8 +74,21 @@ client.perform_belated(DumDum.new, at: Time.now + 5 * 60)
74
74
  client.perform_belated(DumDum.new, max_retries: 3) # default 5
75
75
  ```
76
76
 
77
- Belated runs on localhost, port 8788.
78
- Going to make that an option in the future.
77
+ You can also fetch jobs from the future jobs queue:
78
+
79
+ ```ruby
80
+ job = client.perform_belated(proc { 0 / 0 }, at: Time.now + 5 * 60)
81
+ job = Belated.find job.id # Find the job if it's in the future queue
82
+ # Oh no, that job looks a bit weird!
83
+ # Let's delete it:
84
+ client.perform_belated(
85
+ Belated.delete job.id
86
+ )
87
+ # Yeah... currently you have to send the command through the client like this as a job. :/
88
+ # Maybe the client should handle the deletion?
89
+ ```
90
+
91
+ Belated runs on localhost, port 8788 by default, but the port is configurable, see below.
79
92
 
80
93
  ## Rails
81
94
 
@@ -110,16 +123,30 @@ client.perform_belated(job, Time.now + 1.month)
110
123
 
111
124
  The client also holds references to the jobs that are instances of `Proc` that have been pushed so that they are not collected by GC. This is because procs are passed by reference, and the client needs to keep them alive. They are removed from the list when the job is done.
112
125
 
126
+ There is also a rudimentary admin panel:
127
+ 1. Mount the engine routes
128
+ ```ruby
129
+ # routes.rb
130
+ mount Belated::Engine => '/belated'
131
+ ```
132
+
133
+ Then access it at `/belated/` for job search based on id or see future jobs at `/belated/future_jobs`.
134
+ Warning: Very rudimentary.
135
+
113
136
  # Settings
114
137
 
115
138
  Configuring Belated:
116
139
 
117
140
  ```ruby
118
141
  Belated.configure do |config|
142
+ config.env = 'production' # Defaults to production
119
143
  config.rails = false # default is true
120
144
  config.rails_path = # './dummy' default is '.'
121
145
  config.connect = false # Connect to dRuby, default is true, useful for testing only
122
146
  config.workers = 2 # default is 1
147
+ config.basic_auth.user = 'user' # default is Belated
148
+ config.basic_auth.password = 'password' # default is Belated123
149
+ # Set nil for both if you don't want basic auth
123
150
  end
124
151
  ```
125
152
 
@@ -165,6 +192,7 @@ Belated::Client.test_mode_off! # Turn off inline job processing
165
192
  ## Development
166
193
 
167
194
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
195
+ On Ubuntu, if you have an SQLite install error, try `sudo apt-get install libsqlite3-dev`.
168
196
 
169
197
  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).
170
198
 
@@ -0,0 +1,18 @@
1
+ class Belated
2
+ # Controller in charge of admin side of Belated.
3
+ class AdminController < ::ActionController::Base
4
+ if (name = Belated.basic_auth.name) && (pass = Belated.basic_auth.password)
5
+ http_basic_authenticate_with name: name, password: pass
6
+ end
7
+
8
+ def index
9
+ return unless request.post?
10
+
11
+ @belated = Belated.find params[:job_id]
12
+ end
13
+
14
+ def future_jobs
15
+ @belateds = Belated.all_future_jobs
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ <table class="table jobs">
2
+ <thead>
3
+ <th>
4
+ Job Name
5
+ </th>
6
+ <th>
7
+ Job Time
8
+ </th>
9
+ </thead>
10
+ <%= @belateds.each do |job| %>
11
+ <tr>
12
+ <td>
13
+ <%= job.job.inspect %>
14
+ </td>
15
+ <td>
16
+ <%= job.at %>
17
+ </td>
18
+ </tr>
19
+ <% end %>
20
+ </table>
@@ -0,0 +1,3 @@
1
+ Belated Admin Panel
2
+
3
+ <%= @belated.inspect %>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Belated</title>
5
+
6
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
7
+ </head>
8
+
9
+ <body>
10
+
11
+ <%= yield %>
12
+ </body>
13
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Belated::Engine.routes.draw do
4
+ match '/', to: 'admin#index', via: %i[get post]
5
+ get '/future_jobs', to: 'admin#future_jobs'
6
+ end
@@ -1,5 +1,5 @@
1
1
  class Belated
2
- class Rails < ::Rails::Engine
2
+ class Engine < ::Rails::Engine
3
3
  isolate_namespace Belated
4
4
  end
5
5
  end
data/lib/belated/queue.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'belated/job'
4
3
  require 'belated/logging'
5
4
  require 'belated/job_wrapper'
6
5
  require 'sorted_set'
@@ -21,7 +20,7 @@ class Belated
21
20
  @queue = queue
22
21
  @mutex = Mutex.new
23
22
  self.future_jobs = future_jobs
24
- self.future_jobs_db = PStore.new('future_jobs.pstore', true) # pass true for thread safety
23
+ self.future_jobs_db = PStore.new("future_jobs_#{Belated.env}.pstore", true) # pass true for thread safety
25
24
  end
26
25
 
27
26
  def enqueue_future_jobs
@@ -99,10 +98,13 @@ class Belated
99
98
  true
100
99
  end
101
100
 
102
- private
103
-
104
- def proc_or_shutdown?(job)
105
- job.is_a?(Symbol) || job.job.instance_of?(Proc)
101
+ def find(job_id)
102
+ job = nil
103
+ future_jobs_db.transaction(true) do
104
+ job = future_jobs_db[job_id]
105
+ end
106
+ job = future_jobs.find { |j| j.id == job_id } if job.nil?
107
+ job
106
108
  end
107
109
 
108
110
  def delete_job(job)
@@ -112,6 +114,12 @@ class Belated
112
114
  end
113
115
  end
114
116
 
117
+ private
118
+
119
+ def proc_or_shutdown?(job)
120
+ job.is_a?(Symbol) || job.job.instance_of?(Proc)
121
+ end
122
+
115
123
  def insert_into_future_jobs_db(job)
116
124
  future_jobs_db.transaction do
117
125
  future_jobs_db[job.id] = job
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -42,7 +42,7 @@ class Belated
42
42
  today = Time.now.strftime('%F')
43
43
  return @store if @store&.path&.include?(today)
44
44
 
45
- @store = PStore.new("history-#{today}.pstore", true)
45
+ @store = PStore.new("history_#{Belated.env}-#{today}.pstore", true)
46
46
  end
47
47
  end
48
48
  end
data/lib/belated.rb CHANGED
@@ -6,6 +6,7 @@ require_relative 'belated/worker'
6
6
  require 'belated/client'
7
7
  require 'belated/job_wrapper'
8
8
  require 'belated/queue'
9
+ require 'ruby2_keywords'
9
10
  require 'drb'
10
11
  require 'dry-configurable'
11
12
  require 'logger'
@@ -22,20 +23,25 @@ class Belated
22
23
  extend Dry::Configurable
23
24
  include Logging
24
25
  include Singleton unless $TESTING
25
- @@queue = Belated::Queue.new
26
26
 
27
- setting :rails, true
28
- setting :rails_path, '.'
29
- setting :workers, 1
30
- setting :connect, true
31
- setting :environment, 'development', reader: true
32
- setting :logger, Logger.new($stdout), reader: true
33
- setting :log_level, :info, reader: true
34
- setting :host, 'localhost', reader: true
35
- setting :port, '8788', reader: true
36
- setting :heartbeat, 1, reader: true
37
- setting :client_heartbeat, 5, reader: true
27
+ setting :rails, default: true
28
+ setting :rails_path, default: '.'
29
+ setting :workers, default: 1
30
+ setting :connect, default: true
31
+ setting :env, default: 'production', reader: true
32
+ setting :logger, default: Logger.new($stdout), reader: true
33
+ setting :log_level, default: :info, reader: true
34
+ setting :host, default: 'localhost', reader: true
35
+ setting :port, default: '8788', reader: true
36
+ setting :heartbeat, default: 1, reader: true
37
+ setting :client_heartbeat, default: 5, reader: true
38
+ setting :basic_auth, reader: true do
39
+ setting :name, default: 'Belated'
40
+ setting :password, default: 'Belated123'
41
+ end
42
+
38
43
  URI = "druby://#{Belated.host}:#{Belated.port}"
44
+ @@queue = Belated::Queue.new
39
45
 
40
46
  # Since it's running as a singleton, we need something to start it up.
41
47
  # Aliased for testing purposes.
@@ -65,7 +71,6 @@ class Belated
65
71
  end
66
72
 
67
73
  def trap_signals
68
- pp 'trap'
69
74
  %w[INT TERM].each do |signal|
70
75
  Signal.trap(signal) do
71
76
  @worker_list.length.times do
@@ -85,10 +90,10 @@ class Belated
85
90
  def boot_app
86
91
  return unless rails?
87
92
 
88
- ENV['RAILS_ENV'] ||= Belated.config.environment
93
+ ENV['RAILS_ENV'] ||= Belated.env
89
94
  require File.expand_path("#{Belated.config.rails_path}/config/environment.rb")
90
95
  require 'rails/all'
91
- require 'belated/rails'
96
+ require 'active_job/queue_adapters/belated_adapter'
92
97
  end
93
98
 
94
99
  def rails?
@@ -129,7 +134,7 @@ class Belated
129
134
 
130
135
  def banner_and_info
131
136
  log banner
132
- log "Currently running Belated version #{Belated::VERSION} in #{Belated.config.environment}"
137
+ log "Currently running Belated version #{Belated::VERSION} in #{Belated.env}"
133
138
  log %(Belated running #{@worker_list&.length.to_i} workers on #{URI}...)
134
139
  end
135
140
 
@@ -142,7 +147,12 @@ class Belated
142
147
 
143
148
  class << self
144
149
  def find(job_id)
145
- @@queue.future_jobs.find { |job| job.id == job_id }
150
+ @@queue.find(job_id)
151
+ end
152
+
153
+ def delete(job_id)
154
+ job = find(job_id)
155
+ @@queue.delete_job(job)
146
156
  end
147
157
 
148
158
  def kill_and_clear_queue!
@@ -152,6 +162,10 @@ class Belated
152
162
  clear_queue!
153
163
  end
154
164
 
165
+ def all_future_jobs
166
+ @@queue.future_jobs
167
+ end
168
+
155
169
  def clear_queue!
156
170
  @@queue.clear
157
171
  end
@@ -169,4 +183,7 @@ class Belated
169
183
  @@queue
170
184
  end
171
185
  end
172
- require 'active_job/queue_adapters/belated_adapter' if defined?(::Rails)
186
+ if defined?(::Rails)
187
+ require 'active_job/queue_adapters/belated_adapter'
188
+ require 'belated/engine'
189
+ 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.8.0
4
+ version: 0.9.0
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-09-08 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: drb
@@ -115,20 +115,24 @@ files:
115
115
  - LICENSE.txt
116
116
  - README.md
117
117
  - Rakefile
118
+ - app/controllers/belated/admin_controller.rb
119
+ - app/views/belated/admin/future_jobs.html.erb
120
+ - app/views/belated/admin/index.html.erb
121
+ - app/views/layouts/belated/admin.html.erb
118
122
  - belated.gemspec
119
123
  - bin/belated
120
124
  - bin/bundle
121
125
  - bin/console
122
126
  - bin/setup
127
+ - config/routes.rb
123
128
  - lib/active_job/queue_adapters/belated_adapter.rb
124
129
  - lib/belated.rb
125
130
  - lib/belated/client.rb
131
+ - lib/belated/engine.rb
126
132
  - lib/belated/exceptions.rb
127
- - lib/belated/job.rb
128
133
  - lib/belated/job_wrapper.rb
129
134
  - lib/belated/logging.rb
130
135
  - lib/belated/queue.rb
131
- - lib/belated/rails.rb
132
136
  - lib/belated/testing.rb
133
137
  - lib/belated/version.rb
134
138
  - lib/belated/worker.rb
data/lib/belated/job.rb DELETED
@@ -1 +0,0 @@
1
- Job = Struct.new(:klass, :at)