class BlackStack::NextBot::Command

The “local” (or persistance class) that will load, update and create records in the database.

Public Class Methods

load_next(id_worker) click to toggle source

load the next command to be performed by a certain worker.

# File lib/localcommand.rb, line 26
def self.load_next(id_worker)
  row = DB[
    "SELECT c.id 
    FROM nbcommand c WITH (NOLOCK)
    WHERE c.id_worker = '#{id_worker}'
    AND c.run_end_time IS NULL
    ORDER BY c.create_time ASC"
  ].first
  return nil if row.nil?
  return BlackStack::NextBot::Command.where(:id => row[:id]).first if !row.nil?
end

Public Instance Methods

end(success=true, error_description=nil) click to toggle source

update the end time, success flag and error description of the command.

# File lib/localcommand.rb, line 45
def end(success=true, error_description=nil)
  self.run_end_time = now()
  self.run_success = success
  self.run_error_description = error_description
  self.save
end
start() click to toggle source

update the start time of the command.

# File lib/localcommand.rb, line 39
def start()
  self.run_start_time = now()
  self.save
end
status() click to toggle source

decide the status of this command, based on both the run_start_time, run_end_time and run_error_description

# File lib/localcommand.rb, line 14
def status()
  com = self
  commandstatus = nil
  commandstatus = BlackStack::NextBot::BaseCommand::STATUS_PENDING  if com.run_start_time.nil?
  commandstatus = BlackStack::NextBot::BaseCommand::STATUS_ONGOING  if !com.run_start_time.nil? && com.run_end_time.nil? #&& com.run_error_description.nil?
  commandstatus = BlackStack::NextBot::BaseCommand::STATUS_FAILURE  if !com.run_start_time.nil? && !com.run_end_time.nil? && !com.run_success
  commandstatus = BlackStack::NextBot::BaseCommand::STATUS_SUCCESS  if !com.run_start_time.nil? && !com.run_end_time.nil? && com.run_success
  commandstatus = BlackStack::NextBot::BaseCommand::STATUS_CANCELED if !com.run_start_time.nil? && !com.run_end_time.nil? && com.run_success.nil?
  commandstatus
end
to_hash() click to toggle source

return a hash descriptor of this object, in order to send it to a remote process as a response to an API call.

# File lib/localcommand.rb, line 55
def to_hash()
  ret = {}
  ret[:id] = self.id.to_guid
  ret[:id_worker] = self.id_worker.to_guid
  ret[:type] = self.type
  # start command params
  ret[:param_start_id_lnuser] = self.param_start_id_lnuser
  ret[:param_start_username] = self.param_start_id_lnuser.nil? ? nil : LnUser.where(:id=>self.param_start_id_lnuser).first.username
  # login command params
  ret[:param_login_id_domain] = self.param_login_id_domain.nil? ? nil : self.param_login_id_domain.to_guid
  # goto command params
  ret[:param_goto_url] = self.param_goto_url
  # traffic command params
  proxy = self.param_traffic_id_proxy.nil? ? nil : Proxy.where(:id=>self.param_traffic_id_proxy).first
  ret[:param_traffic_url] = self.param_traffic_url
  ret[:param_traffic_id_proxy] = self.param_traffic_id_proxy
  ret[:param_traffic_proxy_ip] = proxy.nil? ? nil : proxy.ip
  ret[:param_traffic_proxy_port] = proxy.nil? ? nil : proxy.port
  ret[:param_traffic_number_of_visits] = self.param_traffic_number_of_visits
  ret[:param_traffic_visit_min_seconds] = self.param_traffic_visit_min_seconds
  ret[:param_traffic_visit_random_additional_seconds] = self.param_traffic_visit_random_additional_seconds
  # command
  return ret
end