frontkick 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72aa979e5f8b0fcc7424d0db082038483f84dfdc
4
- data.tar.gz: 255712e57011e231886af33fc424185380a65d2b
3
+ metadata.gz: e888a0eeabcd74cf8b17b95b4b8e2caa56eaef29
4
+ data.tar.gz: bf94899be04073e6e1e5a85843c18372c60bbc57
5
5
  SHA512:
6
- metadata.gz: 0e972160b2aba8082fcd4583a36e1694959f10913f4970afe6b10b346e2201f3de6c8d8ae1b878752b22ff09122d8d6787eba8645af377be7fe13b713ecda8fa
7
- data.tar.gz: c22c2214ab5e7f7cf427b1096d00445cea8d6e573e92aeb3317e55ad8e398926b16d01154cf1ebed2a52f5274ead6592f6e24e53e04dd075a982df0baf03fe49
6
+ metadata.gz: c499e15431e89473e96a438f0c06ba84cf3900522a503822e107c24695c5401cac62d0a8066bd4afbc4f784d71766b4be0b550bbf9cd72c9d44a00529f987da2
7
+ data.tar.gz: 3263adc248acab1001ee893ffdadfbe8dcca6037660838800b6035d382f69b82bb2cd4193fd0d2ba9e7dc315ffea575cc124545ab795725e9a94864d68ca144d
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- # 0.0.3 (2013/06/23)
1
+ # 0.2.0 (2013/09/13)
2
+
3
+ Changes:
4
+
5
+ - Support exclusive option
6
+
7
+ # 0.1.0 (2013/06/23)
2
8
 
3
9
  Changes:
4
10
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  testing ruby: 1.9.2, 1.9.3, 2.0.0;
4
4
 
5
- frontkick is a wrapper of Open3#popen3 to execute a command easily.
5
+ Frontkick is a gem to execute a command and obtain status code, stdout, stderr simply, wheres, `system` does not provide it.
6
6
 
7
7
  ## USAGE
8
8
 
@@ -25,6 +25,12 @@ frontkick is a wrapper of Open3#popen3 to execute a command easily.
25
25
 
26
26
  Frontkick::Command.exec("sleep 2 && ls /hoge", :timeout => 1)
27
27
 
28
+ ### Exclusive Option
29
+
30
+ Prohibit another process to run a command concurrently
31
+
32
+ Frontkick::Command.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock") # raises Fontkick::Locked if locked
33
+
28
34
  ## Contributing
29
35
 
30
36
  1. Fork it
data/frontkick.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Naotoshi Seo"]
10
10
  gem.email = ["sonots@gmail.com"]
11
11
  gem.homepage = "https://github.com/sonots/frontkick"
12
- gem.summary = "A wrapper of Open3#popen3 to execute a command easily"
12
+ gem.summary = "Execute a command simply!"
13
13
  gem.description = gem.summary
14
14
 
15
15
  gem.files = `git ls-files`.split($\)
@@ -1,6 +1,11 @@
1
1
  require 'benchmark'
2
2
  require 'open3'
3
3
 
4
+ module Frontkick
5
+ class Locked < StandardError
6
+ end
7
+ end
8
+
4
9
  module Frontkick
5
10
  class Command
6
11
  def self.exec(cmd, opts = {})
@@ -8,6 +13,7 @@ module Frontkick
8
13
  stdin, out, err, wait_thr, pid = nil
9
14
 
10
15
  cmd_array = cmd.kind_of?(Array) ? cmd : [cmd]
16
+ lock_fd = file_lock(opts[:exclusive]) if opts[:exclusive]
11
17
  begin
12
18
  timeout(opts[:timeout]) do # nil is for no timeout
13
19
  duration = Benchmark.realtime do
@@ -32,6 +38,7 @@ module Frontkick
32
38
  out.close if out and !out.closed?
33
39
  err.close if err and !err.closed?
34
40
  wait_thr.kill if wait_thr and !wait_thr.stop?
41
+ lock_fd.flock(File::LOCK_UN)
35
42
  end
36
43
 
37
44
  CommandResult.new(stdout, stderr, exit_code, duration)
@@ -44,5 +51,20 @@ module Frontkick
44
51
  # no child process
45
52
  end
46
53
  end
54
+
55
+ # Use file lock to perfome exclusive operation
56
+ #
57
+ # @param lock_file file path used to lock
58
+ # @return file descriptor
59
+ # @raise Fontkick::Locked if locked
60
+ def self.file_lock(lock_file)
61
+ lock_fd = File.open(lock_file, File::RDWR|File::CREAT, 0644)
62
+ success = lock_fd.flock(File::LOCK_EX|File::LOCK_NB)
63
+ unless success
64
+ lock_fd.flock(File::LOCK_UN)
65
+ raise Frontkick::Locked
66
+ end
67
+ lock_fd
68
+ end
47
69
  end
48
70
  end
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-23 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: A wrapper of Open3#popen3 to execute a command easily
55
+ description: Execute a command simply!
56
56
  email:
57
57
  - sonots@gmail.com
58
58
  executables: []
@@ -92,9 +92,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.0.0
95
+ rubygems_version: 2.0.2
96
96
  signing_key:
97
97
  specification_version: 4
98
- summary: A wrapper of Open3#popen3 to execute a command easily
98
+ summary: Execute a command simply!
99
99
  test_files:
100
100
  - spec/spec_helper.rb
101
+ has_rdoc: