Class: BlackStack::Proxy

Inherits:
Object
  • Object
show all
Includes:
BaseProxy
Defined in:
lib/proxy.rb

Overview

proxy almacenado en la base de datos

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseProxy

#chrome_switches, #firefox_profile_parameter, #phantomjs_switches

Class Method Details

.availablesWithStealth(process, discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish, discretion_seconds_to_wait_if_proxy_has_finished_successfully, discretion_seconds_to_wait_if_proxy_has_been_blocked, discretion_seconds_to_wait_for_long_sleep, discretion_stop_from, discretion_stop_until) ⇒ Object

TODO: deprecated



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/proxy.rb', line 12

def self.availablesWithStealth(
      process, 
      discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish, 
      discretion_seconds_to_wait_if_proxy_has_finished_successfully,
      discretion_seconds_to_wait_if_proxy_has_been_blocked,
      discretion_seconds_to_wait_for_long_sleep,
      discretion_stop_from,
      discretion_stop_until
    )
    
  q =
    "SELECT COUNT(*) c FROM dbo.fnProxyDiscretion(" +
    "'#{process}', " +
    "#{discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish.to_s}, " +
    "#{discretion_seconds_to_wait_if_proxy_has_finished_successfully.to_s}, " +
    "#{discretion_seconds_to_wait_if_proxy_has_been_blocked.to_s}, " +
    "#{discretion_seconds_to_wait_for_long_sleep.to_s}, " +
    "'#{discretion_stop_from.to_s}', " +
    "'#{discretion_stop_until.to_s}')"
  
  return DB[q].first[:c].to_i
end

.getWithStealth(process, discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish, discretion_seconds_to_wait_if_proxy_has_finished_successfully, discretion_seconds_to_wait_if_proxy_has_been_blocked, discretion_seconds_to_wait_for_long_sleep, discretion_stop_from, discretion_stop_until) ⇒ Object

TODO: deprecated



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/proxy.rb', line 36

def self.getWithStealth(
      process, 
      discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish, 
      discretion_seconds_to_wait_if_proxy_has_finished_successfully,
      discretion_seconds_to_wait_if_proxy_has_been_blocked,
      discretion_seconds_to_wait_for_long_sleep,
      discretion_stop_from,
      discretion_stop_until
    )
  rid = guid()
  DB.execute(
    "EXEC dbo.reserveProxyWithDiscretion " +
    "'#{rid}', " +
    "'#{process}', " +
    "#{discretion_seconds_to_wait_if_proxy_has_been_reserved_but_didnt_finish.to_s}, " +
    "#{discretion_seconds_to_wait_if_proxy_has_finished_successfully.to_s}, " +
    "#{discretion_seconds_to_wait_if_proxy_has_been_blocked.to_s}, " +
    "#{discretion_seconds_to_wait_for_long_sleep.to_s}, " +
    "'#{discretion_stop_from.to_s}', " +
    "'#{discretion_stop_until.to_s}'"
  )
  BlackStack::Proxy.where(:reservation_id=>rid).first
end

Instance Method Details

#endJob(id_client, result, description, records_before_long_sleep) ⇒ Object

TODO: deprecated TODO: Reemplazar el parametro records_before_long_sleep por un registro en la tabla PARAMS



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/proxy.rb', line 67

def endJob(id_client, result, description, records_before_long_sleep)
  # => #464
=begin
  DB.execute("UPDATE proxy SET reservation_end_time=GETDATE(), reservation_result='#{result.to_s}', reservation_description='#{description.to_s}' WHERE [id]='#{self.id}'")
  
  DB.execute(
    "EXEC dbo.endProxyJob " +
    "'#{self.id}', " +
    "'#{id_client}', " +
    "#{result.to_s}, " +
    "'#{description.to_s}', " +
    "#{records_before_long_sleep.to_s} "
  )
=end
end

#startJobObject

TODO: deprecated



61
62
63
# File 'lib/proxy.rb', line 61

def startJob()
  DB.execute("UPDATE proxy SET reservation_start_time=GETDATE() WHERE [id]='#{self.id}'")
end