lib/lolcommits/plugin/lolsrv.rb in lolcommits-lolsrv-0.0.4 vs lib/lolcommits/plugin/lolsrv.rb in lolcommits-lolsrv-0.0.5

- old
+ new

@@ -69,31 +69,36 @@ ## # # Post-capture hook, runs after lolcommits captures a snapshot. # - # Syncs lolcommit images to the remote server (forked) + # Syncs lolcommit images to the remote server (forked and detached) # # @return [Integer] forked process id # def run_capture_ready(do_fork: true) - do_fork ? fork { sync } : sync + if do_fork + pid = fork { sync } + Process.detach(pid) + else + sync + end end private ## # # Syncs lolcommmit images to the remote server # - # Fetches from /lols and iterates over shas in the JSON array. Then for - # each image found in the local loldir folder, check if it has already - # been uploaded. If not, upload the image with a POST request and + # Fetches from /lols and iterates over shas in the JSON array. For each + # image found in the local loldir folder, check if it has already been + # uploaded. If not, upload the image with a POST request and # upload_params. # - # Upload requests that fail abort the sync + # Upload requests that fail abort the sync. # def sync print "Syncing lols ... " raise 'failed fetching existing lols' unless existing_shas @@ -104,12 +109,13 @@ raise "failed uploading #{image}" if response.nil? end end print "done!\n" - rescue RuntimeError => e + rescue StandardError => e print "#{e.message} (try again with --debug)\n" + nil end ## # # Fetch and parse JSON response from `server/lols`, returning an array of @@ -122,11 +128,11 @@ @existing_shas ||= begin lols = JSON.parse(RestClient.get(lols_endpoint)) lols.map { |lol| lol['sha'] } rescue JSON::ParserError, SocketError, RestClient::RequestFailed => e log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}") - return nil + nil end end ## # @@ -137,10 +143,10 @@ # def upload(image, sha) RestClient.post(upload_endpoint, upload_params_for(image, sha)) rescue SocketError, RestClient::RequestFailed => e log_error(e, "ERROR: Upload of lol #{sha} to #{upload_endpoint} FAILED #{e.class} - #{e.message}") - return nil + nil end ## # # Hash of params to send with lolcommit upload. Built from repositiory and