rocketjob 3.5.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -1
- data/bin/rocketjob +1 -0
- data/bin/rocketjob_batch_perf +11 -0
- data/lib/rocket_job/batch.rb +32 -0
- data/lib/rocket_job/batch/callbacks.rb +40 -0
- data/lib/rocket_job/batch/io.rb +154 -0
- data/lib/rocket_job/batch/logger.rb +57 -0
- data/lib/rocket_job/batch/lower_priority.rb +54 -0
- data/lib/rocket_job/batch/model.rb +157 -0
- data/lib/rocket_job/batch/performance.rb +99 -0
- data/lib/rocket_job/batch/result.rb +8 -0
- data/lib/rocket_job/batch/results.rb +9 -0
- data/lib/rocket_job/batch/state_machine.rb +102 -0
- data/lib/rocket_job/batch/statistics.rb +88 -0
- data/lib/rocket_job/batch/tabular.rb +56 -0
- data/lib/rocket_job/batch/tabular/input.rb +123 -0
- data/lib/rocket_job/batch/tabular/output.rb +59 -0
- data/lib/rocket_job/batch/throttle.rb +91 -0
- data/lib/rocket_job/batch/throttle_running_slices.rb +53 -0
- data/lib/rocket_job/batch/worker.rb +288 -0
- data/lib/rocket_job/cli.rb +29 -7
- data/lib/rocket_job/config.rb +1 -1
- data/lib/rocket_job/extensions/mongoid/clients/options.rb +37 -0
- data/lib/rocket_job/extensions/mongoid/contextual/mongo.rb +17 -0
- data/lib/rocket_job/extensions/mongoid/factory.rb +4 -4
- data/lib/rocket_job/extensions/mongoid_5/clients/options.rb +38 -0
- data/lib/rocket_job/extensions/mongoid_5/contextual/mongo.rb +64 -0
- data/lib/rocket_job/extensions/mongoid_5/factory.rb +13 -0
- data/lib/rocket_job/jobs/on_demand_batch_job.rb +127 -0
- data/lib/rocket_job/jobs/performance_job.rb +18 -0
- data/lib/rocket_job/jobs/upload_file_job.rb +2 -5
- data/lib/rocket_job/plugins/document.rb +2 -8
- data/lib/rocket_job/plugins/job/persistence.rb +6 -4
- data/lib/rocket_job/plugins/job/throttle.rb +3 -6
- data/lib/rocket_job/plugins/job/worker.rb +2 -2
- data/lib/rocket_job/server.rb +14 -3
- data/lib/rocket_job/sliced/input.rb +336 -0
- data/lib/rocket_job/sliced/output.rb +99 -0
- data/lib/rocket_job/sliced/slice.rb +166 -0
- data/lib/rocket_job/sliced/slices.rb +166 -0
- data/lib/rocket_job/sliced/writer/input.rb +60 -0
- data/lib/rocket_job/sliced/writer/output.rb +82 -0
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocket_job/worker.rb +2 -2
- data/lib/rocketjob.rb +28 -0
- metadata +51 -62
- data/test/config/database.yml +0 -5
- data/test/config/mongoid.yml +0 -88
- data/test/config_test.rb +0 -10
- data/test/dirmon_entry_test.rb +0 -313
- data/test/dirmon_job_test.rb +0 -216
- data/test/files/text.txt +0 -3
- data/test/job_test.rb +0 -71
- data/test/jobs/housekeeping_job_test.rb +0 -102
- data/test/jobs/on_demand_job_test.rb +0 -59
- data/test/jobs/upload_file_job_test.rb +0 -107
- data/test/plugins/cron_test.rb +0 -166
- data/test/plugins/job/callbacks_test.rb +0 -166
- data/test/plugins/job/defaults_test.rb +0 -53
- data/test/plugins/job/logger_test.rb +0 -56
- data/test/plugins/job/model_test.rb +0 -94
- data/test/plugins/job/persistence_test.rb +0 -94
- data/test/plugins/job/state_machine_test.rb +0 -116
- data/test/plugins/job/throttle_test.rb +0 -111
- data/test/plugins/job/worker_test.rb +0 -199
- data/test/plugins/processing_window_test.rb +0 -109
- data/test/plugins/restart_test.rb +0 -193
- data/test/plugins/retry_test.rb +0 -88
- data/test/plugins/singleton_test.rb +0 -92
- data/test/plugins/state_machine_event_callbacks_test.rb +0 -102
- data/test/plugins/state_machine_test.rb +0 -67
- data/test/plugins/transaction_test.rb +0 -84
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +0 -17
@@ -1,67 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module Plugins
|
4
|
-
# Unit Test for RocketJob::Job
|
5
|
-
class StateMachineTest < Minitest::Test
|
6
|
-
class Test
|
7
|
-
include RocketJob::Plugins::Document
|
8
|
-
include RocketJob::Plugins::StateMachine
|
9
|
-
|
10
|
-
field :name, type: String
|
11
|
-
field :state, type: String
|
12
|
-
validates_presence_of :name, :state
|
13
|
-
|
14
|
-
aasm column: :state, whiny_persistence: true do
|
15
|
-
state :pending, initial: true
|
16
|
-
state :enabled
|
17
|
-
|
18
|
-
event :enable do
|
19
|
-
transitions from: :pending, to: :enabled
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe RocketJob::Plugins::StateMachine do
|
25
|
-
before do
|
26
|
-
@doc = Test.new
|
27
|
-
end
|
28
|
-
|
29
|
-
after do
|
30
|
-
@doc.destroy if @doc && !@doc.new_record?
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#create!' do
|
34
|
-
it 'raises an exception when a validation fails on create!' do
|
35
|
-
assert_raises Mongoid::Errors::Validations do
|
36
|
-
@doc = Test.create!
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#save!' do
|
42
|
-
it 'raises an exception when a validation fails on save' do
|
43
|
-
assert_raises Mongoid::Errors::Validations do
|
44
|
-
@doc.save!
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#transition!' do
|
50
|
-
it 'raises an exception when a validation fails on state transition with save' do
|
51
|
-
assert_raises Mongoid::Errors::Validations do
|
52
|
-
@doc.enable!
|
53
|
-
end
|
54
|
-
assert @doc.pending?
|
55
|
-
refute @doc.valid?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#transition' do
|
60
|
-
it 'does not raise an exception when a validation fails on state transition without save' do
|
61
|
-
@doc.enable
|
62
|
-
assert @doc.enabled?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'active_record'
|
3
|
-
|
4
|
-
ActiveRecord::Base.configurations = YAML.safe_load(ERB.new(IO.read('test/config/database.yml')).result)
|
5
|
-
ActiveRecord::Base.establish_connection(:test)
|
6
|
-
|
7
|
-
ActiveRecord::Schema.define version: 0 do
|
8
|
-
create_table :users, force: true do |t|
|
9
|
-
t.string :login
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class User < ActiveRecord::Base
|
14
|
-
end
|
15
|
-
|
16
|
-
module Plugins
|
17
|
-
module Job
|
18
|
-
class TransactionTest < Minitest::Test
|
19
|
-
class CommitTransactionJob < RocketJob::Job
|
20
|
-
# Wrap perform with a transaction, so that it is rolled back on exception.
|
21
|
-
include RocketJob::Plugins::Transaction
|
22
|
-
|
23
|
-
field :login, type: String
|
24
|
-
|
25
|
-
def perform
|
26
|
-
User.create!(login: login)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class RollbackTransactionJob < RocketJob::Job
|
31
|
-
# Wrap perform with a transaction, so that it is rolled back on exception.
|
32
|
-
include RocketJob::Plugins::Transaction
|
33
|
-
|
34
|
-
field :login, type: String
|
35
|
-
|
36
|
-
def perform
|
37
|
-
User.create!(login: login)
|
38
|
-
raise 'This must fail and rollback the transaction'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe RocketJob::Plugins::Job::Logger do
|
43
|
-
before do
|
44
|
-
User.delete_all
|
45
|
-
CommitTransactionJob.delete_all
|
46
|
-
RollbackTransactionJob.delete_all
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
@job.destroy if @job && !@job.new_record?
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#rocket_job_transaction' do
|
54
|
-
it 'is registered' do
|
55
|
-
assert(CommitTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
|
56
|
-
assert(RollbackTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
|
57
|
-
refute(RocketJob::Job.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#perform' do
|
62
|
-
it 'commits on success' do
|
63
|
-
assert_equal 0, User.count
|
64
|
-
job = CommitTransactionJob.new(login: 'Success')
|
65
|
-
job.perform_now
|
66
|
-
assert job.completed?
|
67
|
-
assert_equal 1, User.count
|
68
|
-
assert_equal 'Success', User.first.login
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'rolls back on exception' do
|
72
|
-
assert_equal 0, User.count
|
73
|
-
job = RollbackTransactionJob.new(login: 'Bad')
|
74
|
-
assert_raises RuntimeError do
|
75
|
-
job.perform_now
|
76
|
-
end
|
77
|
-
assert job.failed?
|
78
|
-
assert_equal 0, User.count
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/test/test_db.sqlite3
DELETED
Binary file
|
data/test/test_helper.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
ENV['TZ'] = 'America/New_York'
|
3
|
-
|
4
|
-
require 'yaml'
|
5
|
-
require 'minitest/autorun'
|
6
|
-
require 'minitest/stub_any_instance'
|
7
|
-
require 'awesome_print'
|
8
|
-
require 'rocketjob'
|
9
|
-
|
10
|
-
SemanticLogger.add_appender(file_name: 'test.log', formatter: :color)
|
11
|
-
SemanticLogger.default_level = :debug
|
12
|
-
|
13
|
-
RocketJob::Config.load!('test', 'test/config/mongoid.yml')
|
14
|
-
Mongoid.logger = SemanticLogger[Mongoid]
|
15
|
-
Mongo::Logger.logger = SemanticLogger[Mongo]
|
16
|
-
|
17
|
-
# RocketJob::Job.collection.database.command(dropDatabase: 1)
|