tasks 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +34 -0
  2. data/lib/tasks.rb +16 -0
  3. metadata +56 -0
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Tasks -- Better Process Manager for Ruby
2
+
3
+ ![Traffic Control](http://farm4.static.flickr.com/3118/3204377933_8c978370db.jpg)
4
+
5
+ ## spawn
6
+
7
+ `tasks` provides `spawn` even in ruby 1.8.
8
+
9
+ require 'tasks'
10
+ include Tasks
11
+
12
+ pid = spawn './something.rb'
13
+ ...
14
+ system "kill #{pid}"
15
+
16
+ `spawn` is like system with `'&'` and it also returns the procces id.
17
+
18
+ ## love_pact
19
+
20
+ `tasks` supports a couple to do a love pact.
21
+
22
+ require 'tasks'
23
+ include Tasks
24
+
25
+ master_pid = spawn './master.rb'
26
+ slave_pid = spawn './slave.rb'
27
+
28
+ fork do
29
+ love_pact master_pid, slave_pid
30
+ end
31
+
32
+ If a master died, the slave dies immediately.
33
+
34
+ Note that now `love_pact` works only in UNIX.
data/lib/tasks.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Tasks
2
+ module_function
3
+
4
+ def spawn(*cmd)
5
+ fork { exec(*cmd) }
6
+ end
7
+
8
+ def love_pact(master, slave, interval = 2)
9
+ loop {
10
+ Process.kill 0, master
11
+ sleep interval
12
+ }
13
+ rescue Errno::ESRCH
14
+ Process.kill "KILL", slave
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - ujihisa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-01 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Better Process Manager for Ruby
17
+ email: ujihisa at gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.md
24
+ files:
25
+ - lib/tasks.rb
26
+ - README.md
27
+ has_rdoc: true
28
+ homepage: https://github.com/ujihisa/tasks
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.3.5
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Better Process Manager for Ruby
55
+ test_files: []
56
+