Class: AnswersEngine::Scraper::RubySeederExecutor
- Inherits:
-
Executor
- Object
- Executor
- AnswersEngine::Scraper::RubySeederExecutor
show all
- Defined in:
- lib/answersengine/scraper/ruby_seeder_executor.rb
Constant Summary
Constants inherited
from Executor
Executor::MAX_FIND_OUTPUTS_PER_PAGE
Instance Attribute Summary collapse
Attributes inherited from Executor
#filename, #gid, #job_id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Executor
#clean_backtrace, #eval_with_context, #exec_parser, #find_output, #find_outputs, #finisher_update, #get_content, #get_failed_content, #get_job_id, #init_global_page, #init_job_page, #init_page, #parsing_update, #remove_old_dups!, #remove_old_output_dups!, #remove_old_page_dups!, #save_outputs, #save_pages, #save_pages_and_outputs, #seeding_update
#create_context, #expose_to, #exposed_env, #exposed_methods, #isolated_binding, #var_or_proc
Constructor Details
Returns a new instance of RubySeederExecutor.
6
7
8
9
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 6
def initialize(options={})
@filename = options.fetch(:filename) { raise "Filename is required"}
@job_id = options[:job_id]
end
|
Instance Attribute Details
#save ⇒ Object
Returns the value of attribute save.
4
5
6
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 4
def save
@save
end
|
Class Method Details
.exposed_methods ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 11
def self.exposed_methods
[
:outputs,
:pages,
:save_pages,
:save_outputs,
:find_output,
:find_outputs
].freeze
end
|
Instance Method Details
#eval_seeder_script(save = false) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 33
def eval_seeder_script(save=false)
update_seeding_starting_status
proc = Proc.new do
outputs = []
pages = []
begin
context = isolated_binding({
outputs: outputs,
pages: pages
})
eval_with_context filename, context
rescue SyntaxError => e
handle_error(e) if save
raise e
rescue => e
handle_error(e) if save
raise e
end
puts "=========== Seeding Executed ==========="
begin
save_pages_and_outputs(pages, outputs, :seeding)
rescue => e
handle_error(e) if save
raise e
end
update_seeding_done_status
end
proc.call
end
|
#exec_seeder(save = false) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 22
def exec_seeder(save=false)
@save = save
if save
puts "Executing seeder script"
else
puts "Trying seeder script"
end
eval_seeder_script(save)
end
|
#handle_error(e) ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 109
def handle_error(e)
error = ["Seeding #{e.class}: #{e.to_s} (Job:#{job_id}",clean_backtrace(e.backtrace)].join("\n")
seeding_update(
job_id: job_id,
seeding_status: :failed,
log_error: error)
end
|
#save_type ⇒ Object
67
68
69
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 67
def save_type
:seeding
end
|
#update_seeding_done_status ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 94
def update_seeding_done_status
return unless save
response = seeding_update(
job_id: job_id,
seeding_status: :done)
if response.code == 200
puts "Seeding Done."
else
puts "Error: Unable to save Seeding Done Status to server: #{response.body}"
raise "Unable to save Seeding Done Status to server: #{response.body}"
end
end
|
#update_seeding_starting_status ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 79
def update_seeding_starting_status
return unless save
response = seeding_update(
job_id: job_id,
seeding_status: :starting)
if response.code == 200
puts "Seeding Status Updated."
else
puts "Error: Unable to save Seeding Status to server: #{response.body}"
raise "Unable to save Seeding Status to server: #{response.body}"
end
end
|
#update_to_server(opts = {}) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/answersengine/scraper/ruby_seeder_executor.rb', line 71
def update_to_server(opts = {})
seeding_update(
job_id: opts[:job_id],
pages: opts[:pages],
outputs: opts[:outputs],
seeding_status: opts[:status])
end
|