Class: InternetHakai::BaseAction

Inherits:
Object
  • Object
show all
Defined in:
lib/internethakai/core.rb

Overview

ベースアクション

アクションはこのクラスを継承して作成

Direct Known Subclasses

RequestAction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt, scenario) ⇒ BaseAction

設定ファイルで指定したオプションがわたされる



103
104
105
106
107
108
109
110
# File 'lib/internethakai/core.rb', line 103

def initialize opt, scenario
    @opt = get_default.merge(opt)
    @scenario_handler = BaseHandler::get_handler('ScenarioHandler')
    @queue = BaseHandler::get_handler(opt['queue'])
    @method_quit = method(:quit)
    @scenario = scenario
    @scenario_id = @scenario.object_id
end

Instance Attribute Details

#performance_idObject

Returns the value of attribute performance_id.



111
112
113
# File 'lib/internethakai/core.rb', line 111

def performance_id
  @performance_id
end

Instance Method Details

#dispatch_nextObject



139
140
141
# File 'lib/internethakai/core.rb', line 139

def dispatch_next
    @_on_complete_calback.call if @_on_complete_calback
end

#freeObject

デストラクタ



130
131
132
133
134
135
136
137
138
# File 'lib/internethakai/core.rb', line 130

def free
    #puts "free: #{@_complete}: #{object_id}"
    return if @_complete #1つのリクエストで2回呼ばないように

    @_on_complete_calback.call if @_on_complete_calback
    #@queue.add(@method_quit)
    @scenario_handler.quit_action(@scenario_id)
    @_complete = false
end

#get_defaultObject

オプションのデフォルト値を指定したい場合はここを上書き



114
115
116
# File 'lib/internethakai/core.rb', line 114

def get_default
    {"times"=>1, "follow_redirect"=>true}
end

#has_on_complete?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/internethakai/core.rb', line 121

def has_on_complete?
    not not @_on_complete_calback
end

#quitObject



142
143
144
# File 'lib/internethakai/core.rb', line 142

def quit
    @scenario_handler.quit_action(@scenario_id)
end

#runObject

コマンドの中身



125
126
127
128
# File 'lib/internethakai/core.rb', line 125

def run
    @_complete = false
    #Thread.current[:heartbeat] = Time::now
end

#set_on_complete(&block) ⇒ Object



118
119
120
# File 'lib/internethakai/core.rb', line 118

def set_on_complete &block
    @_on_complete_calback = block
end