batch_manager 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.rdoc +9 -3
- data/lib/batch_manager/batch_status.rb +3 -7
- data/lib/batch_manager/executor.rb +1 -1
- data/lib/batch_manager/monitor.rb +14 -2
- data/lib/batch_manager/railtie.rb +1 -1
- data/lib/batch_manager/utils.rb +14 -4
- data/lib/batch_manager/version.rb +1 -1
- data/lib/generators/batch/batch_generator.rb +1 -1
- data/lib/generators/batch_manager/migration/templates/active_record/migration.rb +1 -1
- data/lib/tasks/batch_manager_tasks.rake +24 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDVkYjIwYTM5NjUxNzliYjE1NDVkNDdmZTg1YmI1ZjRhN2M2NTE5NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWZmZWNjM2Q0ZDdjNGU2MGRiMjg4Njc0ODg2ZjI5Njk3ZmRjYmFmOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTZlOWM0ZTg2NzcxN2YzZjQ0ODg2ZDM5NjkwNTFmYTRhOTYzNWY1MmE1OTk4
|
10
|
+
NWIzOGQ1NDMyYTkxMGUyOTA2MmJhNjI3YzQ3YTliOTJhY2U2ZWNhYzJmNDYx
|
11
|
+
NmI0YTdmZDQzMzQzM2ZkYTE1NmEyMTQ1NzA5NjMyMDI5MDc4ODE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWQ1Yzk2ODhjMzEwNDQ0YWUxMzcxYzkxNWRiMGIwYjA0OWM0YTdiMTBmMGU3
|
14
|
+
ODZlN2QwNDMzNTExM2IwZmRjOTQ1Zjk1MGYxOTE2ZGE4NDk2NmRhOTAwOGEx
|
15
|
+
M2UxNjI1OTcxYmFmMmIyMjRjY2ZhODBkNTM2MzVlYzk3NDFjMjI=
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= BatchManager
|
1
|
+
= BatchManager {<img src="https://travis-ci.org/cctiger36/batch_manager.png?branch=master" alt="Build Status" />}[https://travis-ci.org/cctiger36/batch_manager] {<img src="https://badge.fury.io/rb/batch_manager.png" alt="Gem Version" />}[http://badge.fury.io/rb/batch_manager]
|
2
2
|
|
3
3
|
A rails plugin to manage batch scripts similar to migrations.
|
4
4
|
|
@@ -33,7 +33,7 @@ You can change the default configuration in config/application.rb
|
|
33
33
|
|
34
34
|
This will generate the file 'test.rb' in the configured batch_dir with default template.
|
35
35
|
|
36
|
-
You can
|
36
|
+
You can find the template in lib/generators/batch/templates, and modify it for yourself.
|
37
37
|
|
38
38
|
== Batch Header
|
39
39
|
|
@@ -61,7 +61,13 @@ Please use this command instead of 'rails runner' to run batch scripts.
|
|
61
61
|
|
62
62
|
== Rake Tasks
|
63
63
|
|
64
|
-
|
64
|
+
show all batches
|
65
|
+
|
66
|
+
bundle exec rake batch:list
|
67
|
+
|
68
|
+
show the details of batches
|
69
|
+
|
70
|
+
bundle exec rake batch:details
|
65
71
|
|
66
72
|
== TODO
|
67
73
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module BatchManager
|
2
2
|
class BatchStatus
|
3
|
-
|
3
|
+
include BatchManager::Utils
|
4
|
+
attr_accessor :name, :created_at, :times_limit, :auto_run, :group_name, :managed
|
4
5
|
|
5
6
|
def initialize(path)
|
6
|
-
@
|
7
|
-
@name = File.basename(path, ".rb")
|
7
|
+
@name = batch_name(path)
|
8
8
|
File.open path do |f|
|
9
9
|
f.each_line do |line|
|
10
10
|
parse_batch_content line
|
@@ -30,10 +30,6 @@ module BatchManager
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def to_s
|
34
|
-
# TODO
|
35
|
-
end
|
36
|
-
|
37
33
|
def managed?
|
38
34
|
@managed
|
39
35
|
end
|
@@ -3,7 +3,7 @@ module BatchManager
|
|
3
3
|
include BatchManager::Utils
|
4
4
|
|
5
5
|
def self.exec(batch_file, options)
|
6
|
-
batch_file_path =
|
6
|
+
batch_file_path = batch_full_path(batch_file)
|
7
7
|
if File.exist?(batch_file_path)
|
8
8
|
batch_status = BatchManager::BatchStatus.new(batch_file_path)
|
9
9
|
if options[:force] || batch_status.can_run?
|
@@ -3,8 +3,20 @@ module BatchManager
|
|
3
3
|
include BatchManager::Utils
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def
|
7
|
-
|
6
|
+
def batches
|
7
|
+
arr = []
|
8
|
+
Dir.glob(File.join(BatchManager.batch_dir, "**", "*.rb")).sort.each do |f|
|
9
|
+
arr << batch_name(f)
|
10
|
+
end
|
11
|
+
arr
|
12
|
+
end
|
13
|
+
|
14
|
+
def details
|
15
|
+
status_array = []
|
16
|
+
Dir.glob(File.join(BatchManager.batch_dir, "**", "*.rb")).sort.each do |f|
|
17
|
+
status_array << BatchManager::BatchStatus.new(f)
|
18
|
+
end
|
19
|
+
status_array
|
8
20
|
end
|
9
21
|
|
10
22
|
def status(file_name)
|
@@ -3,7 +3,7 @@ require 'rails'
|
|
3
3
|
module BatchManager
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
rake_tasks do
|
6
|
-
Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
|
6
|
+
Dir[File.join(File.dirname(__FILE__), '../tasks/*.rake')].each { |f| load f }
|
7
7
|
end
|
8
8
|
|
9
9
|
config.batch_manager = ActiveSupport::OrderedOptions.new
|
data/lib/batch_manager/utils.rb
CHANGED
@@ -6,12 +6,22 @@ module BatchManager
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module OverallMethods
|
9
|
-
def
|
10
|
-
if
|
11
|
-
|
9
|
+
def batch_name(filename_or_path)
|
10
|
+
if filename_or_path.start_with?(::BatchManager.batch_dir)
|
11
|
+
path = filename_or_path.sub("#{::BatchManager.batch_dir}/", "")
|
12
12
|
else
|
13
|
-
|
13
|
+
path = filename_or_path
|
14
14
|
end
|
15
|
+
path.sub(".rb", "")
|
16
|
+
end
|
17
|
+
|
18
|
+
def batch_full_path(filename_or_path)
|
19
|
+
if filename_or_path.start_with?(::BatchManager.batch_dir)
|
20
|
+
path = filename_or_path
|
21
|
+
else
|
22
|
+
path = File.join(::BatchManager.batch_dir, filename_or_path)
|
23
|
+
end
|
24
|
+
path.end_with?(".rb") ? path : path + ".rb"
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
@@ -1,6 +1,28 @@
|
|
1
|
-
desc "Execute batch"
|
2
1
|
namespace :batch do
|
2
|
+
desc "List all batches"
|
3
3
|
task :list do
|
4
|
-
|
4
|
+
puts BatchManager::Monitor.batches
|
5
|
+
end
|
6
|
+
|
7
|
+
task :details => :environment do
|
8
|
+
title = "%-12s" % "Managed?"
|
9
|
+
title << "%-50s" % "Name"
|
10
|
+
title << "%10s" % "Ran/Limit"
|
11
|
+
title << "%25s" % "Last run at"
|
12
|
+
title << "%25s" % "Created at"
|
13
|
+
puts title
|
14
|
+
BatchManager::Monitor.details.each do |status|
|
15
|
+
schema_batch = status.schema_batch
|
16
|
+
str = "%-12s" % (status.managed?? "Yes" : "")
|
17
|
+
str << "%-50s" % status.name.truncate(45)
|
18
|
+
str << "%10s" % "#{schema_batch.try(:ran_times).to_i}/#{status.times_limit || 0}"
|
19
|
+
if last_ran_at = schema_batch.try(:last_ran_at)
|
20
|
+
str << "%25s" % last_ran_at.strftime('%Y-%m-%d %H:%M:%S')
|
21
|
+
else
|
22
|
+
str << "%25s" % ""
|
23
|
+
end
|
24
|
+
str << "%25s" % status.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
25
|
+
puts str
|
26
|
+
end
|
5
27
|
end
|
6
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batch_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weihu Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|