rocketjob 3.0.0.alpha → 3.0.0.beta
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/lib/rocket_job/jobs/housekeeping_job.rb +17 -17
- data/lib/rocket_job/plugins/job/model.rb +1 -1
- data/lib/rocket_job/plugins/restart.rb +9 -0
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocketjob.rb +1 -0
- data/test/dirmon_job_test.rb +1 -1
- data/test/jobs/housekeeping_job_test.rb +59 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd04a62d8fb3d214ff56c777828061bf9f0e6453
|
4
|
+
data.tar.gz: 2d86b6a765140aac78ad0083514689c2f1d0ab4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de693c53a87019be64dddcde01944eeacf37c0bbc1229130927bb70307a42656c393acc65bc0a0f57045a4b8ba91bd3020ae828a0ab8e980f7bac49215c4b723
|
7
|
+
data.tar.gz: 3f9327e7d49bfac112788b331fb532a55d6bd748f66cbccf43f08d75d1a3412168e2a62182cb354c4648605b349d619a412b41f37231294bd1101328491196b9
|
@@ -15,39 +15,39 @@ module RocketJob
|
|
15
15
|
# aborted_retention: 7.days,
|
16
16
|
# completed_retention: 7.days,
|
17
17
|
# failed_retention: 14.days,
|
18
|
-
# paused_retention:
|
18
|
+
# paused_retention: nil,
|
19
19
|
# queued_retention: nil
|
20
20
|
# )
|
21
21
|
#
|
22
|
-
# Example, overriding defaults and disabling removal of
|
22
|
+
# Example, overriding defaults and disabling removal of failed jobs:
|
23
23
|
# RocketJob::Jobs::HousekeepingJob.create!(
|
24
24
|
# aborted_retention: 1.day,
|
25
|
-
# completed_retention:
|
26
|
-
# failed_retention:
|
27
|
-
# paused_retention: nil
|
25
|
+
# completed_retention: 30.minutes,
|
26
|
+
# failed_retention: nil
|
28
27
|
# )
|
29
28
|
class HousekeepingJob < RocketJob::Job
|
30
29
|
include RocketJob::Plugins::Cron
|
31
30
|
include RocketJob::Plugins::Singleton
|
32
31
|
|
33
|
-
self.priority =
|
32
|
+
self.priority = 25
|
34
33
|
self.description = 'Cleans out historical jobs'
|
35
|
-
|
34
|
+
# Runs hourly on the hour
|
35
|
+
self.cron_schedule = '0 * * * * America/New_York'
|
36
36
|
|
37
37
|
# Retention intervals in seconds
|
38
38
|
# Set to nil to not
|
39
|
-
field :aborted_retention, Integer, default: 7.days
|
40
|
-
field :completed_retention, Integer, default: 7.days
|
41
|
-
field :failed_retention, Integer, default: 14.days
|
42
|
-
field :paused_retention,
|
43
|
-
field :queued_retention, Integer
|
39
|
+
field :aborted_retention, type: Integer, default: 7.days
|
40
|
+
field :completed_retention, type: Integer, default: 7.days
|
41
|
+
field :failed_retention, type: Integer, default: 14.days
|
42
|
+
field :paused_retention, type: Integer
|
43
|
+
field :queued_retention, type: Integer
|
44
44
|
|
45
45
|
def perform
|
46
|
-
RocketJob::Job.aborted.where(created_at: {'$lte' => aborted_retention.ago}).destroy_all if aborted_retention
|
47
|
-
RocketJob::Job.completed.where(created_at: {'$lte' => completed_retention.ago}).destroy_all if completed_retention
|
48
|
-
RocketJob::Job.failed.where(created_at: {'$lte' => failed_retention.ago}).destroy_all if failed_retention
|
49
|
-
RocketJob::Job.paused.where(created_at: {'$lte' => paused_retention.ago}).destroy_all if paused_retention
|
50
|
-
RocketJob::Job.queued.where(created_at: {'$lte' => queued_retention.ago}).destroy_all if queued_retention
|
46
|
+
RocketJob::Job.aborted.where(created_at: {'$lte' => aborted_retention.seconds.ago}).destroy_all if aborted_retention
|
47
|
+
RocketJob::Job.completed.where(created_at: {'$lte' => completed_retention.seconds.ago}).destroy_all if completed_retention
|
48
|
+
RocketJob::Job.failed.where(created_at: {'$lte' => failed_retention.seconds.ago}).destroy_all if failed_retention
|
49
|
+
RocketJob::Job.paused.where(created_at: {'$lte' => paused_retention.seconds.ago}).destroy_all if paused_retention
|
50
|
+
RocketJob::Job.queued.where(created_at: {'$lte' => queued_retention.seconds.ago}).destroy_all if queued_retention
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -46,7 +46,7 @@ module RocketJob
|
|
46
46
|
# Can be used to reduce log noise, especially during high volume calls
|
47
47
|
# For debugging a single job can be logged at a low level such as :trace
|
48
48
|
# Levels supported: :trace, :debug, :info, :warn, :error, :fatal
|
49
|
-
field :log_level, type: Symbol, user_editable: true
|
49
|
+
field :log_level, type: Symbol, class_attribute: true, user_editable: true
|
50
50
|
|
51
51
|
#
|
52
52
|
# Read-only attributes
|
@@ -27,6 +27,15 @@ module RocketJob
|
|
27
27
|
after_fail :rocket_job_restart_abort
|
28
28
|
end
|
29
29
|
|
30
|
+
module ClassMethods
|
31
|
+
def field(name, options)
|
32
|
+
if options.delete(:copy_on_restart) == false
|
33
|
+
self.rocket_job_restart_excludes += [name.to_sym] unless rocket_job_restart_excludes.include?(name.to_sym)
|
34
|
+
end
|
35
|
+
super(name, options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
30
39
|
private
|
31
40
|
|
32
41
|
# Run again in the future, even if this run fails with an exception
|
data/lib/rocket_job/version.rb
CHANGED
data/lib/rocketjob.rb
CHANGED
data/test/dirmon_job_test.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
# Unit Test for RocketJob::Job
|
4
|
+
class HousekeepingJobTest < Minitest::Test
|
5
|
+
class TestJob < RocketJob::Job
|
6
|
+
def perform
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe RocketJob::Jobs::HousekeepingJob do
|
11
|
+
before do
|
12
|
+
HousekeepingJobTest::TestJob.delete_all
|
13
|
+
RocketJob::Jobs::HousekeepingJob.delete_all
|
14
|
+
|
15
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 2.days.ago)
|
16
|
+
job.abort!
|
17
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 8.days.ago)
|
18
|
+
job.abort!
|
19
|
+
|
20
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 2.days.ago)
|
21
|
+
job.perform_now
|
22
|
+
job.save!
|
23
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 8.days.ago)
|
24
|
+
job.perform_now
|
25
|
+
job.save!
|
26
|
+
|
27
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 2.days.ago)
|
28
|
+
job.fail!
|
29
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 15.days.ago)
|
30
|
+
job.fail!
|
31
|
+
|
32
|
+
job = HousekeepingJobTest::TestJob.new(created_at: 400.days.ago)
|
33
|
+
job.pause!
|
34
|
+
job = HousekeepingJobTest::TestJob.new
|
35
|
+
job.pause!
|
36
|
+
|
37
|
+
HousekeepingJobTest::TestJob.create!(created_at: 15.days.ago)
|
38
|
+
HousekeepingJobTest::TestJob.create!
|
39
|
+
|
40
|
+
assert_equal 10, HousekeepingJobTest::TestJob.count, -> { HousekeepingJobTest::TestJob.all.to_a.ai }
|
41
|
+
end
|
42
|
+
|
43
|
+
after do
|
44
|
+
@job.destroy if @job && !@job.new_record?
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'perform' do
|
48
|
+
it 'destroys jobs' do
|
49
|
+
@job = RocketJob::Jobs::HousekeepingJob.new
|
50
|
+
@job.perform_now
|
51
|
+
assert_equal 1, HousekeepingJobTest::TestJob.aborted.count, -> { HousekeepingJobTest::TestJob.aborted.to_a.ai }
|
52
|
+
assert_equal 1, HousekeepingJobTest::TestJob.completed.count, -> { HousekeepingJobTest::TestJob.completed.to_a.ai }
|
53
|
+
assert_equal 1, HousekeepingJobTest::TestJob.failed.count, -> { HousekeepingJobTest::TestJob.failed.to_a.ai }
|
54
|
+
assert_equal 2, HousekeepingJobTest::TestJob.paused.count, -> { HousekeepingJobTest::TestJob.paused.to_a.ai }
|
55
|
+
assert_equal 2, HousekeepingJobTest::TestJob.queued.count, -> { HousekeepingJobTest::TestJob.queued.to_a.ai }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- test/dirmon_job_test.rb
|
120
120
|
- test/files/text.txt
|
121
121
|
- test/job_test.rb
|
122
|
+
- test/jobs/housekeeping_job_test.rb
|
122
123
|
- test/plugins/cron_test.rb
|
123
124
|
- test/plugins/job/callbacks_test.rb
|
124
125
|
- test/plugins/job/defaults_test.rb
|
@@ -164,6 +165,7 @@ test_files:
|
|
164
165
|
- test/dirmon_job_test.rb
|
165
166
|
- test/files/text.txt
|
166
167
|
- test/job_test.rb
|
168
|
+
- test/jobs/housekeeping_job_test.rb
|
167
169
|
- test/plugins/cron_test.rb
|
168
170
|
- test/plugins/job/callbacks_test.rb
|
169
171
|
- test/plugins/job/defaults_test.rb
|