example/batch_sample.rb in keystone-0.0.29 vs example/batch_sample.rb in keystone-0.0.30

- old
+ new

@@ -1,24 +1,36 @@ +# -*- coding: utf-8 -*- require 'rubygems' require 'keystone' require "optparse" -include Keystone::Batch::Base -# 実行時に--helpでオプション一覧 +class SampleBatch + include Keystone::Batch::Base + logger_name :l -has_option = {} -opts = option_parser -opts.on("-v value") do |v| - has_option[:v] = v + # 実行時に--helpでオプション一覧 + def main + has_option = {} + opts = option_parser + opts.on("-v value") do |v| + has_option[:v] = v + end + opts.on("-w who") do |v| + has_option[:w] = v + end + + execute() do + begin + sleep 10 + l.info "batch process01" + l.info "who=#{has_option[:w]}" + sleep 4 + rescue => e + l.error e + end + end + end end -opts.on("-w who") do |v| - has_option[:w] = v -end -execute() do - sleep 10 - info "batch process01" - info "who=#{has_option[:w]}" - sleep 4 - raise 'error occur' -end +batch = SapmleBatch.new +batch.main \ No newline at end of file