deadly_serious 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/deadly_serious.gemspec +25 -0
- data/lib/deadly_serious/engine/channel.rb +31 -0
- data/lib/deadly_serious/engine/json_io.rb +19 -0
- data/lib/deadly_serious/engine/json_process.rb +13 -0
- data/lib/deadly_serious/engine/spawner.rb +96 -0
- data/lib/deadly_serious/processes/db_source.rb +17 -0
- data/lib/deadly_serious/processes/joiner.rb +15 -0
- data/lib/deadly_serious/processes/splitter.rb +14 -0
- data/lib/deadly_serious/version.rb +3 -0
- data/lib/deadly_serious.rb +10 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec9c559df6b61f7d20e04438c3dc3490980c8ada
|
4
|
+
data.tar.gz: dff2f683847b2698ca28ec8d65a462b146459db0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d184d82f4adcf1942ad52a12ba06e494b4d6de28dbfadaececf14363a91f4608d065aa0764041345c5497b1687e2c066cd74aca33c2091e85ba4cbf2f3fa80f
|
7
|
+
data.tar.gz: a5cd61a69a593298904e9a7446496bd6bd77a2f6c4506ab45a8e7af69f7cdc2391d08f38635bb323497b1f0b64cee35dbd72b641201726b01f5fbedd58073309
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ronie Uliana
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# DeadlySerious
|
2
|
+
|
3
|
+
Flow Based Programming Engine mechanically sympathetic to \*nix.
|
4
|
+
|
5
|
+
Flow Based Programming engine that relies on named pipes and Linux processes (sorry, it not works on Windows right now). That means it uses "mechanical sympathy" with the Operating System, i.e., the S.O. is *part* of the program, it's not something *below* it.
|
6
|
+
|
7
|
+
**REQUIRES** Ruby 2.0 and a \*nix based SO (tested on *Ubuntu* and *Arch Linux*)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'deadly_serious'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install deadly_serious
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deadly_serious/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'deadly_serious'
|
8
|
+
spec.version = DeadlySerious::VERSION
|
9
|
+
spec.authors = ['Ronie Uliana']
|
10
|
+
spec.email = ['ronie.uliana@gmail.com']
|
11
|
+
spec.description = %q{Flow Based Programming Engine mechanically sympathetic to *nix.}
|
12
|
+
spec.summary = %q{Flow Based Programming engine that relies on named pipes and Linux processes (sorry, it not works on Windows right now). That means it uses 'mechanical sympathy' with the Operating System, i.e., the S.O. is *part* of the program, it's not something *below* it.}
|
13
|
+
spec.homepage = 'https://github.com/ruliana/deadly_serious'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_dependency 'json'
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DeadlySerious
|
2
|
+
module Engine
|
3
|
+
class Channel
|
4
|
+
def initialize(name, dir: nil)
|
5
|
+
matcher = name.match(/^(>?)(.*)$/)
|
6
|
+
@type = matcher[1] == '>' ? :file : :pipe
|
7
|
+
name = matcher[2]
|
8
|
+
@io_name = "#{dir}/#{name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
return if File.exist?(@io_name)
|
13
|
+
if @type == :file
|
14
|
+
`touch #{@io_name}`
|
15
|
+
else
|
16
|
+
`mkfifo #{@io_name}`
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def open_reader
|
21
|
+
fail %(File "#{@io_name}" not found) unless File.exist?(@io_name)
|
22
|
+
open(@io_name, 'r')
|
23
|
+
end
|
24
|
+
|
25
|
+
def open_writer
|
26
|
+
fail %(File "#{@io_name}" not found) unless File.exist?(@io_name)
|
27
|
+
open(@io_name, 'w')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module DeadlySerious
|
4
|
+
module Engine
|
5
|
+
class JsonIo
|
6
|
+
def initialize(io)
|
7
|
+
@io = io
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
@io.each { |line| yield JSON.parse(line) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(value)
|
15
|
+
@io << value.to_json << "\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'deadly_serious/engine/json_io'
|
2
|
+
|
3
|
+
module DeadlySerious
|
4
|
+
module Engine
|
5
|
+
module JsonProcess
|
6
|
+
def run(readers: [], writers: [])
|
7
|
+
json_readers = readers.map { |it| JsonIo.new(it) }
|
8
|
+
json_writers = writers.map { |it| JsonIo.new(it) }
|
9
|
+
super(readers: json_readers, writers: json_writers)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'deadly_serious/engine/channel'
|
3
|
+
|
4
|
+
module DeadlySerious
|
5
|
+
module Engine
|
6
|
+
class Spawner
|
7
|
+
def initialize(pipe_dir: "/tmp/deadly_serious/#{Process.pid}", preserve_pipe_dir: false)
|
8
|
+
@pipe_dir = pipe_dir
|
9
|
+
@ids = []
|
10
|
+
|
11
|
+
FileUtils.mkdir_p(pipe_dir) unless File.exist?(pipe_dir)
|
12
|
+
|
13
|
+
unless preserve_pipe_dir
|
14
|
+
at_exit { FileUtils.rm_r(pipe_dir, force: true, secure: true) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.dasherize(a_string)
|
19
|
+
a_string.gsub(/(.)([A-Z])/, '\1-\2').downcase.gsub(/\W+/, '-')
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_process_name(name)
|
23
|
+
$0 = "ruby #{self.class.dasherize(name)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_pipe(pipe_name)
|
27
|
+
Channel.new(pipe_name, dir: @pipe_dir).create
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_pipe(pipe_name)
|
31
|
+
Channel.new(pipe_name, dir: @pipe_dir).open_reader
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_pipe(pipe_name)
|
35
|
+
channel = Channel.new(pipe_name, dir: @pipe_dir)
|
36
|
+
return channel.open_writer unless block_given?
|
37
|
+
|
38
|
+
channel.open_writer do |io|
|
39
|
+
yield io
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def fork_it
|
44
|
+
@ids << fork do
|
45
|
+
yield
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def wait_children
|
50
|
+
@ids.each { |id| Process.wait(id) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def kill_children
|
54
|
+
@ids.each { |id| Process.kill('SIGTERM', id) }
|
55
|
+
Process.wait
|
56
|
+
end
|
57
|
+
|
58
|
+
def spawn_source(a_class, *args, writer: self.class.dasherize(a_class.name))
|
59
|
+
create_pipe(writer)
|
60
|
+
fork_it do
|
61
|
+
set_process_name(a_class.name)
|
62
|
+
write_pipe(writer) do
|
63
|
+
a_class.new.run(io, *args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def spawn_process(a_class, *args, readers: [], writers: [])
|
69
|
+
writers.each { |writer| create_pipe(writer) }
|
70
|
+
fork_it do
|
71
|
+
set_process_name(a_class.name)
|
72
|
+
open_readers = readers.map { |reader| read_pipe(reader) }
|
73
|
+
open_writers = writers.map { |writer| write_pipe(writer) }
|
74
|
+
begin
|
75
|
+
a_class.new.run(*args, readers: open_readers, writers: open_writers)
|
76
|
+
ensure
|
77
|
+
open_writers.each { |writer| writer.close unless writer.closed? }
|
78
|
+
open_readers.each { |reader| reader.close unless reader.closed? }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def run
|
84
|
+
run_pipeline
|
85
|
+
wait_children
|
86
|
+
rescue Exception => e
|
87
|
+
kill_children
|
88
|
+
raise e
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
if __FILE__ == $0
|
95
|
+
DeadlySerious::Engine::Spawner.new.run
|
96
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'deadly_serious/engine/json_io'
|
2
|
+
|
3
|
+
module DeadlySerious
|
4
|
+
module Processes
|
5
|
+
module DbSource
|
6
|
+
def run(writer)
|
7
|
+
run(JsonIo.new(writer))
|
8
|
+
end
|
9
|
+
|
10
|
+
def for_each_record(sql)
|
11
|
+
connection.select_all(sql).each do |row|
|
12
|
+
yield row
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DeadlySerious
|
2
|
+
module Processes
|
3
|
+
class Joiner
|
4
|
+
def run(readers: [], writers: [])
|
5
|
+
writer = writers.first
|
6
|
+
until readers.all?(&:eof?)
|
7
|
+
readers.each do |reader|
|
8
|
+
line = reader.gets
|
9
|
+
writer << line if line
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'deadly_serious/version'
|
2
|
+
require 'deadly_serious/engine/spawner'
|
3
|
+
|
4
|
+
# Loading all predefined processes
|
5
|
+
Dir[File.dirname(__FILE__) + '/deadly_serious/processes/*.rb'].each do |file|
|
6
|
+
require File.dirname(file) + '/' + File.basename(file, File.extname(file))
|
7
|
+
end
|
8
|
+
|
9
|
+
module DeadlySerious
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deadly_serious
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ronie Uliana
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Flow Based Programming Engine mechanically sympathetic to *nix.
|
56
|
+
email:
|
57
|
+
- ronie.uliana@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- deadly_serious.gemspec
|
68
|
+
- lib/deadly_serious.rb
|
69
|
+
- lib/deadly_serious/engine/channel.rb
|
70
|
+
- lib/deadly_serious/engine/json_io.rb
|
71
|
+
- lib/deadly_serious/engine/json_process.rb
|
72
|
+
- lib/deadly_serious/engine/spawner.rb
|
73
|
+
- lib/deadly_serious/processes/db_source.rb
|
74
|
+
- lib/deadly_serious/processes/joiner.rb
|
75
|
+
- lib/deadly_serious/processes/splitter.rb
|
76
|
+
- lib/deadly_serious/version.rb
|
77
|
+
homepage: https://github.com/ruliana/deadly_serious
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Flow Based Programming engine that relies on named pipes and Linux processes
|
101
|
+
(sorry, it not works on Windows right now). That means it uses 'mechanical sympathy'
|
102
|
+
with the Operating System, i.e., the S.O. is *part* of the program, it's not something
|
103
|
+
*below* it.
|
104
|
+
test_files: []
|