active_batch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/active_batch/application.js +13 -0
- data/app/assets/javascripts/active_batch/batches.js +2 -0
- data/app/assets/javascripts/active_batch/jobs.js +2 -0
- data/app/assets/stylesheets/active_batch/application.css +15 -0
- data/app/assets/stylesheets/active_batch/batches.css +4 -0
- data/app/assets/stylesheets/active_batch/jobs.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/active_batch/application_controller.rb +4 -0
- data/app/controllers/active_batch/batches_controller.rb +49 -0
- data/app/controllers/active_batch/work_units_controller.rb +29 -0
- data/app/helpers/active_batch/application_helper.rb +4 -0
- data/app/helpers/active_batch/batches_helper.rb +4 -0
- data/app/helpers/active_batch/jobs_helper.rb +4 -0
- data/app/jobs/active_batch/batch_scheduler_job.rb +16 -0
- data/app/jobs/active_batch/batch_status_check_job.rb +17 -0
- data/app/models/active_batch/batch.rb +28 -0
- data/app/models/active_batch/work_unit.rb +17 -0
- data/app/views/active_batch/batches/_form.html.erb +21 -0
- data/app/views/active_batch/batches/index.html.erb +30 -0
- data/app/views/active_batch/batches/new.html.erb +5 -0
- data/app/views/active_batch/batches/show.html.erb +31 -0
- data/app/views/active_batch/work_units/index.html.erb +26 -0
- data/app/views/active_batch/work_units/show.html.erb +18 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20150319101734_create_active_batch_tables.rb +21 -0
- data/lib/active_batch.rb +8 -0
- data/lib/active_batch/batched_job.rb +36 -0
- data/lib/active_batch/engine.rb +5 -0
- data/lib/active_batch/transactional_batched_job.rb +15 -0
- data/lib/active_batch/version.rb +3 -0
- data/lib/tasks/active_batch_tasks.rake +4 -0
- data/test/active_batch_test.rb +7 -0
- data/test/controllers/active_batch/batches_controller_test.rb +45 -0
- data/test/controllers/active_batch/work_units_controller_test.rb +32 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/schema.rb +34 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +10238 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7e439048c89c95bfde77609c4b119aef +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/91621687e7dac71b8a566c4dbcecde96 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9d1c7539b482b1c2ffa085bd26729895 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b706477a353ac2248f013097788efb85 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/c23568af9c4b124555ced351478e21cd +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ca1c23ae80a4f7e2f04c1e9aa40d2d42 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d8510a98424b7a23248a15c9151f0daf +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e00f432644dd66e5bd6ae31eafdd9511 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ec9d2f32f08b260672f48c6e00ac3c8b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ed1bbbbceac3d159210843f2da897105 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f603fd5b82c54beb733ddc055fd6daf1 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f762c0c4cbb8ace1fa3d7f760c74f6c8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7afdd8c341387bba687dddcc3ee6d50 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f9920f7a4f1a87f298d2df81feb570e5 +0 -0
- data/test/fixtures/active_batch/batches.yml +5 -0
- data/test/fixtures/active_batch/work_units.yml +5 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/jobs/active_batch/batch_scheduler_job_test.rb +41 -0
- data/test/jobs/active_batch/batch_status_check_job_test.rb +51 -0
- data/test/jobs/batch_job.rb +21 -0
- data/test/jobs/rescue_job.rb +9 -0
- data/test/lib/active_batch/batched_job_test.rb +21 -0
- data/test/models/active_batch/batch_test.rb +9 -0
- data/test/models/active_batch/work_unit_test.rb +19 -0
- data/test/test_helper.rb +21 -0
- metadata +236 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveBatch
|
4
|
+
class BatchSchedulerJobTest < ActiveJob::TestCase
|
5
|
+
include ActiveJob::TestHelper
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@batch_job = 'BatchJob'
|
9
|
+
@test_string = 'test'
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'enqueues work unit jobs and check job' do
|
13
|
+
BatchSchedulerJob.perform_now(@batch_job, @test_string)
|
14
|
+
assert_enqueued_jobs(@test_string.length + 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'creates batch' do
|
18
|
+
assert_difference('WorkUnit.count', @test_string.length) do
|
19
|
+
BatchSchedulerJob.perform_now(@batch_job, @test_string)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'creates work units' do
|
24
|
+
assert_difference('Batch.count', 1) do
|
25
|
+
BatchSchedulerJob.perform_now(@batch_job, @test_string)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'batch has work units' do
|
30
|
+
job = BatchSchedulerJob.perform_now(@batch_job, @test_string)
|
31
|
+
batch = Batch.find_by(job_id: job.job_id)
|
32
|
+
assert_equal @test_string.length, batch.work_units.count
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'work units have enqueued status' do
|
36
|
+
job = BatchSchedulerJob.perform_now(@batch_job, @test_string)
|
37
|
+
batch = Batch.find_by(job_id: job.job_id)
|
38
|
+
assert_equal @test_string.length, batch.work_units.enqueued.count
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveBatch
|
4
|
+
class BatchStatusCheckJobTest < ActiveJob::TestCase
|
5
|
+
|
6
|
+
fixtures :all
|
7
|
+
|
8
|
+
def random_result
|
9
|
+
rand(100).to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
setup do
|
13
|
+
@first_result = random_result
|
14
|
+
@second_result = random_result
|
15
|
+
@batch = active_batch_batches(:one)
|
16
|
+
@work_unit_done = @batch.work_units.create(status: :done, work_result: @first_result)
|
17
|
+
@work_unit_running = @batch.work_units.create(status: :running, work_result: @second_result)
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'reenqueues itself later if batch is not done' do
|
21
|
+
assert_enqueued_with(job: BatchStatusCheckJob, args: [@batch]) do
|
22
|
+
BatchStatusCheckJob.perform_now(@batch)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'uses the same queue than the work_units' do
|
27
|
+
assert_enqueued_with(job: BatchStatusCheckJob, queue: 'test_queue') do
|
28
|
+
BatchStatusCheckJob.perform_now(@batch)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'does not reenqueue itself later if batch is done' do
|
33
|
+
@work_unit_running.status = :done
|
34
|
+
@work_unit_running.save
|
35
|
+
assert_no_enqueued_jobs do
|
36
|
+
BatchStatusCheckJob.perform_now(@batch)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'calls after batch with proper args when batch is done' do
|
41
|
+
@work_unit_running.update!(status: :done)
|
42
|
+
BatchStatusCheckJob.perform_now(@batch)
|
43
|
+
|
44
|
+
assert File.exists?('/tmp/batch_job_result')
|
45
|
+
assert File.exists?('/tmp/batch_job_arguments')
|
46
|
+
assert_equal @batch.arguments.first, IO.read('/tmp/batch_job_arguments')
|
47
|
+
assert_equal [@first_result, @second_result].to_s, IO.read('/tmp/batch_job_result')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class BatchJob < ActiveJob::Base
|
2
|
+
include ActiveBatch::BatchedJob
|
3
|
+
|
4
|
+
queue_as :test_queue
|
5
|
+
|
6
|
+
def self.each_work_unit(string)
|
7
|
+
string.each_char do |char|
|
8
|
+
yield char
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.after_batch(args, results)
|
13
|
+
File.open('/tmp/batch_job_arguments', 'w') { |f| f << args.first }
|
14
|
+
File.open('/tmp/batch_job_result', 'w') { |f| f << results }
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform(char)
|
18
|
+
save_result(char)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveBatch
|
4
|
+
class BatchedJobTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test 'can save work result' do
|
7
|
+
@batched_job = BatchJob.new
|
8
|
+
@work_unit = WorkUnit.create(job_id: @batched_job.job_id)
|
9
|
+
@batched_job.save_result('blah')
|
10
|
+
assert_equal 'blah', @work_unit.reload.work_result
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'sets status to failed on exception' do
|
14
|
+
@rescue_job = RescueJob.new
|
15
|
+
@work_unit = WorkUnit.create(job_id: @rescue_job.job_id)
|
16
|
+
@rescue_job.perform_now rescue nil
|
17
|
+
assert @work_unit.reload.failed?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveBatch
|
4
|
+
class JobTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@done_work_unit = WorkUnit.create(status: :done)
|
8
|
+
@running_work_unit = WorkUnit.create(status: :running)
|
9
|
+
@enqueued_work_unit = WorkUnit.create(status: :enqueued)
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'not done scope returns work unit not done' do
|
13
|
+
assert_includes WorkUnit.not_done, @running_work_unit
|
14
|
+
assert_includes WorkUnit.not_done, @enqueued_work_unit
|
15
|
+
refute_includes WorkUnit.not_done, @done_work_unit
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|