fasten 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fasten.gemspec +36 -0
- data/lib/fasten/dag.rb +83 -0
- data/lib/fasten/executor.rb +88 -0
- data/lib/fasten/log_support.rb +23 -0
- data/lib/fasten/task.rb +17 -0
- data/lib/fasten/version.rb +5 -0
- data/lib/fasten.rb +35 -0
- metadata +150 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4a27dfb2f022703bc4565d85e3d013c64c0405c46fff2024b22226e98dd8fc6f
|
|
4
|
+
data.tar.gz: 19a023dbae6572e318a408057e292e685b8fd060bae0caa0cab108e00b044c70
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3eac77c5b0cb9e2eec8482d5b526c4314a1600af7cd70574eca81b43899b068e806db57aa3c730b4e251c73e6f16116ac329c16d3dfb827f9f3a1b084a6f0514
|
|
7
|
+
data.tar.gz: 98e60f25cbc70056d714904c6c73440ca5dc3eb60aaa7241800095a5f34df6cdc8147217f4e6b013ea7bc2af5c3e9cb3d7a2e8fb5f8a89a259ac39b2ddc15411
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fasten
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.5.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at a@a0.cl. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
fasten (0.1.0)
|
|
5
|
+
binding_of_caller
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
ast (2.4.0)
|
|
11
|
+
binding_of_caller (0.8.0)
|
|
12
|
+
debug_inspector (>= 0.0.1)
|
|
13
|
+
coderay (1.1.2)
|
|
14
|
+
debug_inspector (0.0.3)
|
|
15
|
+
diff-lcs (1.3)
|
|
16
|
+
jaro_winkler (1.5.1)
|
|
17
|
+
method_source (0.9.0)
|
|
18
|
+
parallel (1.12.1)
|
|
19
|
+
parser (2.5.1.2)
|
|
20
|
+
ast (~> 2.4.0)
|
|
21
|
+
powerpack (0.1.2)
|
|
22
|
+
pry (0.11.3)
|
|
23
|
+
coderay (~> 1.1.0)
|
|
24
|
+
method_source (~> 0.9.0)
|
|
25
|
+
rainbow (3.0.0)
|
|
26
|
+
rake (10.5.0)
|
|
27
|
+
rspec (3.8.0)
|
|
28
|
+
rspec-core (~> 3.8.0)
|
|
29
|
+
rspec-expectations (~> 3.8.0)
|
|
30
|
+
rspec-mocks (~> 3.8.0)
|
|
31
|
+
rspec-core (3.8.0)
|
|
32
|
+
rspec-support (~> 3.8.0)
|
|
33
|
+
rspec-expectations (3.8.1)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.8.0)
|
|
36
|
+
rspec-mocks (3.8.0)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.8.0)
|
|
39
|
+
rspec-support (3.8.0)
|
|
40
|
+
rubocop (0.59.2)
|
|
41
|
+
jaro_winkler (~> 1.5.1)
|
|
42
|
+
parallel (~> 1.10)
|
|
43
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
44
|
+
powerpack (~> 0.1)
|
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
46
|
+
ruby-progressbar (~> 1.7)
|
|
47
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
48
|
+
ruby-progressbar (1.10.0)
|
|
49
|
+
unicode-display_width (1.4.0)
|
|
50
|
+
|
|
51
|
+
PLATFORMS
|
|
52
|
+
ruby
|
|
53
|
+
|
|
54
|
+
DEPENDENCIES
|
|
55
|
+
bundler (~> 1.16)
|
|
56
|
+
fasten!
|
|
57
|
+
pry
|
|
58
|
+
rake (~> 10.0)
|
|
59
|
+
rspec (~> 3.0)
|
|
60
|
+
rubocop
|
|
61
|
+
|
|
62
|
+
BUNDLED WITH
|
|
63
|
+
1.16.6
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Servicios A0 SpA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Fasten your seatbelts!
|
|
2
|
+
|
|
3
|
+
FIXME: Add intro here
|
|
4
|
+
|
|
5
|
+
## Roadmap
|
|
6
|
+
|
|
7
|
+
- [✔︎] define task to be run to reach a goal, with dependencies (similar to rake, make, and others)
|
|
8
|
+
- [✔︎] run task in parallel by default
|
|
9
|
+
- [ ] dynamicly change the number of worker processes
|
|
10
|
+
- [✔︎] allow to programatically define new tasks
|
|
11
|
+
- [ ] allow to programatically redefine existing tasks
|
|
12
|
+
- [ ] keep each task log in a separate file, to easily debug errors
|
|
13
|
+
- [ ] early stop in case of a failure
|
|
14
|
+
- [✔︎] for non-tty execution, report with a simple progress log in STDOUT
|
|
15
|
+
- [ ] calculate ETA of script, based on previos executions of the same script
|
|
16
|
+
- [ ] for tty execution: start in background and provide a curses interface. When quit, the background process will keep running
|
|
17
|
+
- [ ] provide a cli for running simple tasks
|
|
18
|
+
- [ ] the cli can control (pause/stop/resume) other running executions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Add this line to your application's Gemfile:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
gem 'fasten'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
And then execute:
|
|
30
|
+
|
|
31
|
+
$ bundle
|
|
32
|
+
|
|
33
|
+
Or install it yourself as:
|
|
34
|
+
|
|
35
|
+
$ gem install fasten
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
TODO: Write usage instructions here
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
44
|
+
|
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fasten. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
54
|
+
|
|
55
|
+
## Code of Conduct
|
|
56
|
+
|
|
57
|
+
Everyone interacting in the Fasten project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fasten/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'fasten'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
require 'pry'
|
|
11
|
+
Pry.start
|
|
12
|
+
|
|
13
|
+
# require 'irb'
|
|
14
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/fasten.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require 'fasten/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'fasten'
|
|
7
|
+
spec.version = Fasten::VERSION
|
|
8
|
+
spec.authors = ['Aldrin Martoq']
|
|
9
|
+
spec.email = ['contacto@a0.cl']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Fasten your seatbelts! Run jobs in parallel, intelligently.'
|
|
12
|
+
spec.description = 'Fasten your seatbelts! Run jobs in parallel, intelligently.'
|
|
13
|
+
spec.homepage = 'https://github.com/a0/fasten/'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = 'exe'
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ['lib']
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
26
|
+
spec.add_development_dependency 'pry'
|
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
29
|
+
spec.add_development_dependency 'rubocop'
|
|
30
|
+
|
|
31
|
+
spec.add_runtime_dependency 'binding_of_caller'
|
|
32
|
+
|
|
33
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
|
34
|
+
|
|
35
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
36
|
+
end
|
data/lib/fasten/dag.rb
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Fasten
|
|
2
|
+
class DAG
|
|
3
|
+
include Fasten::LogSupport
|
|
4
|
+
attr_reader :tasks, :pending, :done
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@tasks = {}
|
|
8
|
+
@done = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def add(task)
|
|
12
|
+
raise "Task '#{task.name}' already defined" if tasks[task.name]
|
|
13
|
+
|
|
14
|
+
@waiting = nil
|
|
15
|
+
tasks[task.name] = task
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update_task(task, **opts)
|
|
19
|
+
opts.each { |key, val| task[key] = val }
|
|
20
|
+
|
|
21
|
+
return unless task.done
|
|
22
|
+
|
|
23
|
+
@done << task
|
|
24
|
+
@pending.delete task
|
|
25
|
+
task.dependants.each do |dependant_task|
|
|
26
|
+
dependant_task.depends -= 1
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
update_waiting
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def next_task
|
|
33
|
+
waiting.pop
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def waiting
|
|
37
|
+
return @waiting if @waiting
|
|
38
|
+
|
|
39
|
+
reset_tasks
|
|
40
|
+
setup_tasks_dependencies
|
|
41
|
+
@waiting = []
|
|
42
|
+
update_waiting
|
|
43
|
+
|
|
44
|
+
@waiting
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def update_waiting
|
|
50
|
+
move_list = @pending.select do |task|
|
|
51
|
+
task.depends.zero?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@pending -= move_list
|
|
55
|
+
@waiting += move_list
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def reset_tasks
|
|
59
|
+
@pending = []
|
|
60
|
+
@done = []
|
|
61
|
+
tasks.each do |_key, task|
|
|
62
|
+
task.dependants = []
|
|
63
|
+
task.depends = 0
|
|
64
|
+
@pending << task unless task.done
|
|
65
|
+
@done << task if task.done
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def setup_tasks_dependencies
|
|
70
|
+
@pending.each do |task|
|
|
71
|
+
next unless task.after
|
|
72
|
+
|
|
73
|
+
[task.after].flatten.each do |after|
|
|
74
|
+
after_task = after.is_a?(Task) ? after : tasks[after]
|
|
75
|
+
raise "Dependency task '#{after}' not found on task '#{task.name}'." unless after_task
|
|
76
|
+
|
|
77
|
+
task.depends += 1
|
|
78
|
+
after_task.dependants << task
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module Fasten
|
|
2
|
+
class Executor < Task
|
|
3
|
+
include Fasten::LogSupport
|
|
4
|
+
|
|
5
|
+
def initialize(name: nil, max_child: 8)
|
|
6
|
+
super name: name || $PROGRAM_NAME
|
|
7
|
+
self.max_childs = max_child
|
|
8
|
+
|
|
9
|
+
self.pid = $PID
|
|
10
|
+
self.tasks = {}
|
|
11
|
+
self.dag = Fasten::DAG.new
|
|
12
|
+
self.running = false
|
|
13
|
+
self.child_jobs = {}
|
|
14
|
+
self.running_tasks = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add(task)
|
|
18
|
+
dag.add task
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def perform
|
|
22
|
+
log_ini self
|
|
23
|
+
self.ini = Time.new
|
|
24
|
+
self.running = true
|
|
25
|
+
|
|
26
|
+
perform_loop
|
|
27
|
+
|
|
28
|
+
self.fin = Time.new
|
|
29
|
+
log_fin self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
def log_ini(object)
|
|
35
|
+
log_info "Init #{dag.done.count + running_tasks.count}/#{dag.tasks.count} #{object.class} #{object} "
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def log_fin(object)
|
|
39
|
+
log_info "Done #{dag.done.count}/#{dag.tasks.count} #{object.class} #{object} in #{object.fin - object.ini}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def perform_loop
|
|
43
|
+
while running
|
|
44
|
+
next_task = dag.next_task
|
|
45
|
+
|
|
46
|
+
wait_children next_task
|
|
47
|
+
run_next_task next_task
|
|
48
|
+
|
|
49
|
+
self.running = !(next_task.nil? && child_jobs.empty? && dag.waiting.empty?)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
wait_remaining
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def wait_children(next_task)
|
|
56
|
+
return unless (next_task.nil? && !child_jobs.empty?) || child_jobs.count >= max_childs
|
|
57
|
+
|
|
58
|
+
pid = Process.wait(0)
|
|
59
|
+
done_task = child_jobs.delete pid
|
|
60
|
+
return unless done_task
|
|
61
|
+
|
|
62
|
+
dag.update_task done_task, done: true, fin: Time.new
|
|
63
|
+
running_tasks.delete done_task
|
|
64
|
+
|
|
65
|
+
log_fin done_task
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def run_next_task(next_task)
|
|
69
|
+
return unless next_task
|
|
70
|
+
|
|
71
|
+
running_tasks << next_task
|
|
72
|
+
log_ini next_task
|
|
73
|
+
|
|
74
|
+
next_task.ini = Time.new
|
|
75
|
+
pid = fork do
|
|
76
|
+
next_task.perform
|
|
77
|
+
end
|
|
78
|
+
child_jobs[pid] = next_task
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def wait_remaining
|
|
82
|
+
child_jobs.each do |child_pid, child_task|
|
|
83
|
+
Process.wait child_pid
|
|
84
|
+
dag.update_task child_task, done: true
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Fasten
|
|
2
|
+
class << self
|
|
3
|
+
attr_accessor :logger
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
module LogSupport
|
|
7
|
+
%w[debug info error].each do |method|
|
|
8
|
+
define_method "log_#{method}" do |msg|
|
|
9
|
+
return unless Fasten.logger.respond_to?(method)
|
|
10
|
+
|
|
11
|
+
caller = Kernel.binding.of_caller(1).eval('self')
|
|
12
|
+
Fasten.logger.send(method, caller.class) { msg }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Fasten.logger ||=
|
|
19
|
+
begin
|
|
20
|
+
Logger.new(STDOUT, level: Logger::INFO, progname: $PROGRAM_NAME)
|
|
21
|
+
rescue StandardError
|
|
22
|
+
nil
|
|
23
|
+
end
|
data/lib/fasten/task.rb
ADDED
data/lib/fasten.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'English'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'binding_of_caller'
|
|
6
|
+
require 'logger'
|
|
7
|
+
require 'ostruct'
|
|
8
|
+
|
|
9
|
+
require 'fasten/log_support'
|
|
10
|
+
require 'fasten/task'
|
|
11
|
+
require 'fasten/dag'
|
|
12
|
+
require 'fasten/executor'
|
|
13
|
+
require 'fasten/version'
|
|
14
|
+
|
|
15
|
+
module Fasten
|
|
16
|
+
class << self
|
|
17
|
+
include Fasten::LogSupport
|
|
18
|
+
|
|
19
|
+
def load(path)
|
|
20
|
+
executor = Fasten::Executor.new
|
|
21
|
+
|
|
22
|
+
YAML.safe_load(File.read(path)).each do |name, params|
|
|
23
|
+
params.each do |key, val|
|
|
24
|
+
next unless val.is_a?(String) && (match = %r{^/(.+)/$}.match(val))
|
|
25
|
+
|
|
26
|
+
params[key] = Regexp.new(match[1])
|
|
27
|
+
end
|
|
28
|
+
executor.add Fasten::Task.new({ name: name }.merge(params))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
log_info "Loaded #{executor.dag.tasks.count} tasks from #{path}"
|
|
32
|
+
executor
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fasten
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aldrin Martoq
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-10-09 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.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry
|
|
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: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: binding_of_caller
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Fasten your seatbelts! Run jobs in parallel, intelligently.
|
|
98
|
+
email:
|
|
99
|
+
- contacto@a0.cl
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".rspec"
|
|
106
|
+
- ".rubocop.yml"
|
|
107
|
+
- ".ruby-gemset"
|
|
108
|
+
- ".ruby-version"
|
|
109
|
+
- ".travis.yml"
|
|
110
|
+
- CODE_OF_CONDUCT.md
|
|
111
|
+
- Gemfile
|
|
112
|
+
- Gemfile.lock
|
|
113
|
+
- LICENSE.txt
|
|
114
|
+
- README.md
|
|
115
|
+
- Rakefile
|
|
116
|
+
- bin/console
|
|
117
|
+
- bin/setup
|
|
118
|
+
- fasten.gemspec
|
|
119
|
+
- lib/fasten.rb
|
|
120
|
+
- lib/fasten/dag.rb
|
|
121
|
+
- lib/fasten/executor.rb
|
|
122
|
+
- lib/fasten/log_support.rb
|
|
123
|
+
- lib/fasten/task.rb
|
|
124
|
+
- lib/fasten/version.rb
|
|
125
|
+
homepage: https://github.com/a0/fasten/
|
|
126
|
+
licenses:
|
|
127
|
+
- MIT
|
|
128
|
+
metadata:
|
|
129
|
+
allowed_push_host: https://rubygems.org
|
|
130
|
+
post_install_message:
|
|
131
|
+
rdoc_options: []
|
|
132
|
+
require_paths:
|
|
133
|
+
- lib
|
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
|
+
requirements:
|
|
141
|
+
- - ">="
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
version: '0'
|
|
144
|
+
requirements: []
|
|
145
|
+
rubyforge_project:
|
|
146
|
+
rubygems_version: 2.7.6
|
|
147
|
+
signing_key:
|
|
148
|
+
specification_version: 4
|
|
149
|
+
summary: Fasten your seatbelts! Run jobs in parallel, intelligently.
|
|
150
|
+
test_files: []
|