FIX: Don't crawl in test mode, raise correct exception when parameters
are missing
This commit is contained in:
parent
7e3ea5d644
commit
7e0028ba50
|
@ -45,6 +45,9 @@ module Jobs
|
||||||
|
|
||||||
# Fetch the beginning of a HTML document at a url
|
# Fetch the beginning of a HTML document at a url
|
||||||
def self.fetch_beginning(url)
|
def self.fetch_beginning(url)
|
||||||
|
# Never crawl in test mode
|
||||||
|
return if Rails.env.test?
|
||||||
|
|
||||||
uri = final_uri(url)
|
uri = final_uri(url)
|
||||||
return "" unless uri
|
return "" unless uri
|
||||||
|
|
||||||
|
@ -66,6 +69,8 @@ module Jobs
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
raise Discourse::InvalidParameters.new(:topic_link_id) unless args[:topic_link_id].present?
|
raise Discourse::InvalidParameters.new(:topic_link_id) unless args[:topic_link_id].present?
|
||||||
|
|
||||||
|
begin
|
||||||
topic_link = TopicLink.where(id: args[:topic_link_id], internal: false, crawled_at: nil).first
|
topic_link = TopicLink.where(id: args[:topic_link_id], internal: false, crawled_at: nil).first
|
||||||
return if topic_link.blank?
|
return if topic_link.blank?
|
||||||
|
|
||||||
|
@ -84,10 +89,11 @@ module Jobs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception
|
rescue Exception
|
||||||
# If there was a connection error, do nothing
|
# If there was a connection error, do nothing
|
||||||
ensure
|
ensure
|
||||||
topic_link.update_column(:crawled_at, Time.now) if !crawled && topic_link.present?
|
topic_link.update_column(:crawled_at, Time.now) if !crawled && topic_link.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue