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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTBlMjliMWM1NTkyODk0ODkxNjRlYjRlM2FkNTFjNWZlMzZhYmI2OA==
4
+ NDVkYjIwYTM5NjUxNzliYjE1NDVkNDdmZTg1YmI1ZjRhN2M2NTE5NQ==
5
5
  data.tar.gz: !binary |-
6
- MWIyMTAyZjEzYjRlMDQzNzU2ZWZlMzU2YzU2MzU2Zjc1MmY3MjI5Nw==
6
+ MWZmZWNjM2Q0ZDdjNGU2MGRiMjg4Njc0ODg2ZjI5Njk3ZmRjYmFmOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGZjODhjZmYxODgwZWE3ODAxMjFjMmQ3YmY1ZDMxYzMyN2YzMDU4OWNlNzZk
10
- ZjRlMDNmNDFiMjdjZGUwNWNmMmIzNDdmNWQ5MTAwYzk0ZmZhZjA3ZTk4MTU3
11
- ZjA3NGEzMmNjZDRhZTZhZjc0YjZiNWVhMTZkYTc1MDQ4MGRiN2E=
9
+ NTZlOWM0ZTg2NzcxN2YzZjQ0ODg2ZDM5NjkwNTFmYTRhOTYzNWY1MmE1OTk4
10
+ NWIzOGQ1NDMyYTkxMGUyOTA2MmJhNjI3YzQ3YTliOTJhY2U2ZWNhYzJmNDYx
11
+ NmI0YTdmZDQzMzQzM2ZkYTE1NmEyMTQ1NzA5NjMyMDI5MDc4ODE=
12
12
  data.tar.gz: !binary |-
13
- MWUzMzEyOWNhM2RhZTU5MjlkZWEzMDk1YTA5M2JhOTAwZDBkOTBkZjczYTAz
14
- YWY5NDM1ZThjM2M4ZDM5ODc2Yjg4ZDdmMjZhZDJkNzM0ODUxNDdlZDdkNDgz
15
- NmIxZWUzZTliZTVjZDQ5ZDdjZTZmN2NkOGEzYmJlNzhmMTZmYmM=
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 look up the template in lib/generators/batch/templates, and modify it for yourself.
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
- # TODO: rake batch:list
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
- attr_accessor :name, :created_at, :times_limit, :auto_run, :group_name, :path, :managed
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
- @path = path
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 = batch_path(batch_file)
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 list
7
- # TODO
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
@@ -6,12 +6,22 @@ module BatchManager
6
6
  end
7
7
 
8
8
  module OverallMethods
9
- def batch_path(file)
10
- if file.start_with?(::BatchManager.batch_dir)
11
- file
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
- File.join(::BatchManager.batch_dir, file) + ".rb"
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,3 +1,3 @@
1
1
  module BatchManager
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -13,7 +13,7 @@ module Rails
13
13
  end
14
14
 
15
15
  def create_batch_file
16
- template 'batch.rb', "#{BatchManager.batch_dir}/#{file_name}.rb"
16
+ template 'batch.rb', File.join(BatchManager.batch_dir, class_path, "#{file_name}.rb")
17
17
  end
18
18
  end
19
19
  end
@@ -3,7 +3,7 @@ class BatchManagerMigration < ActiveRecord::Migration
3
3
  create_table :schema_batches do |t|
4
4
  t.string :name
5
5
  t.integer :ran_times, :default => 0
6
- t.string :last_ran_at
6
+ t.datetime :last_ran_at
7
7
  end
8
8
  add_index :schema_batches, :name
9
9
  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
- # TODO
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.2
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-24 00:00:00.000000000 Z
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails