This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract PidFile and logging out of Tunnel
- Loading branch information
Showing
10 changed files
with
175 additions
and
102 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'fileutils' | ||
|
||
module ShopifyCli | ||
module Helpers | ||
class PidFile | ||
class << self | ||
RUN_DIR = File.join(ShopifyCli::TEMP_DIR, 'sv') | ||
|
||
def for(identifier) | ||
pid, time = File.read(pid_path_for(identifier)).split(':') | ||
new(identifier, pid: Integer(pid), time: time) | ||
rescue Errno::ENOENT | ||
nil | ||
end | ||
|
||
def write(pid_file) | ||
FileUtils.mkdir_p(File.dirname(pid_file.pid_path)) | ||
File.write(pid_file.pid_path, "#{pid_file.pid}:#{pid_file.time}") | ||
end | ||
|
||
def pid_path_for(identifier) | ||
File.join(RUN_DIR, "#{identifier}.pid") | ||
end | ||
|
||
def log_path_for(identifier) | ||
File.join(RUN_DIR, "#{identifier}.log") | ||
end | ||
end | ||
|
||
attr_reader :identifier, :pid, :time | ||
|
||
def initialize(identifier, pid:, time: Time.now.strftime('%s')) | ||
@identifier = identifier | ||
@pid = pid | ||
@time = time | ||
end | ||
|
||
def pid_path | ||
@pid_path ||= PidFile.pid_path_for(@identifier) | ||
end | ||
|
||
def log_path | ||
@log_path ||= PidFile.log_path_for(@identifier) | ||
end | ||
|
||
def unlink_log | ||
File.unlink(log_path) | ||
nil | ||
rescue Errno::ENOENT | ||
nil | ||
end | ||
|
||
def unlink | ||
File.unlink(pid_path) | ||
nil | ||
rescue Errno::ENOENT | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'test_helper' | ||
|
||
module ShopifyCli | ||
module Helpers | ||
class PidFileTest < MiniTest::Test | ||
def setup | ||
@pid_file = PidFile.new('web', pid: 1234) | ||
end | ||
|
||
def test_pid_has_expected_attributes | ||
assert_equal(1234, @pid_file.pid) | ||
assert_equal('web', @pid_file.identifier) | ||
assert_equal( | ||
File.join(ShopifyCli::TEMP_DIR, 'sv/web.pid'), @pid_file.pid_path | ||
) | ||
assert_equal( | ||
File.join(ShopifyCli::TEMP_DIR, 'sv/web.log'), @pid_file.log_path | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.