Skip to content

Commit

Permalink
have to move db connection back to where the connection is actually n…
Browse files Browse the repository at this point in the history
…eeded (#170)

* have to move db connection back to where it's needed. Otherwise idling connections will be timed out on PostgreSQL
  • Loading branch information
weiweishi authored Sep 18, 2018
1 parent 6001240 commit 8d71774
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/pushmi_pullyu/aip/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def make_file_set_directories(file_set_uuid)

def clean_directories
return unless File.exist?(@aip_directory)

PushmiPullyu.logger.debug("#{@noid}: Nuking directories ...")
FileUtils.rm_rf(@aip_directory)
end
Expand Down
1 change: 1 addition & 0 deletions lib/pushmi_pullyu/aip/fedora_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def download_object(download_path, url_extra: nil,
return true
elsif response.is_a?(Net::HTTPNotFound)
raise FedoraFetchError unless optional

return false
else
raise FedoraFetchError
Expand Down
3 changes: 3 additions & 0 deletions lib/pushmi_pullyu/aip/file_list_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def extract_list_source_uuids
break if next_proxy.nil?

raise NextPreviousProxyMismatch if this_proxy != find_prev_proxy(next_proxy)

this_proxy = next_proxy
end

Expand All @@ -76,6 +77,7 @@ def find_first_proxy
first_uri = statement.object
# Validate that the first proxy doesn't have a previous one
raise FirstProxyHasPrev, @uri.to_s if find_prev_proxy(first_uri)

return first_uri
end
raise NoFirstProxyFound, @uri.to_s
Expand All @@ -86,6 +88,7 @@ def find_last_proxy
last_uri = statement.object
# Validate that the last proxy doesn't have a next one
raise LastProxyHasNext, @uri.to_s if find_next_proxy(last_uri)

return last_uri
end
raise LastProxyFound, @uri.to_s
Expand Down
12 changes: 12 additions & 0 deletions lib/pushmi_pullyu/aip/owner_email_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(rdf_string)
end

def run
setup_db_connection
is_modified = false
prefixes = nil
# Read once to load prefixes (the @things at the top of an n3 file)
Expand All @@ -32,7 +33,18 @@ def run
end
end
return new_body if is_modified

raise NoOwnerPredicate
end

private

def setup_db_connection
ActiveRecord::Base.establish_connection(database_configuration)
end

def database_configuration
PushmiPullyu.options[:database][:url]
end

end
9 changes: 0 additions & 9 deletions lib/pushmi_pullyu/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def start_server
setup_signal_traps

setup_log
setup_db_connection
print_banner

run_tick_loop
Expand Down Expand Up @@ -276,12 +275,4 @@ def start_server_as_daemon
end
end

def setup_db_connection
ActiveRecord::Base.establish_connection(database_configuration)
end

def database_configuration
PushmiPullyu.options[:database][:url]
end

end
1 change: 1 addition & 0 deletions lib/pushmi_pullyu/preservation_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def wait_next_item
while PushmiPullyu.continue_polling?
element = next_item
return element if element.present?

sleep @poll_interval
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pushmi_pullyu/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PushmiPullyu
VERSION = '1.0.4'.freeze
VERSION = '1.0.5'.freeze
end

0 comments on commit 8d71774

Please sign in to comment.