rake-multilogs 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 +4 -4
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -0
- data/Rakefile +1 -0
- data/lib/rake/multilogs.rb +43 -0
- data/lib/rake/multilogs/fork.rb +1 -0
- data/lib/rake/multilogs/task.rb +4 -0
- data/lib/rake/multilogs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f75135ee16d2687d59a5a8b7e4fd6f51e605641780e954616c1baacf43691f
|
4
|
+
data.tar.gz: 5d86280f61247d95e3f2404ad196c63b9895dc6be16103fa456f4dcd1098e8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d9613373228fc4b73f4279285a081781fec14fd165a2fd6c5944e05364bcd8f0bf6c41f04bd64146291f7a410f17086a74e55436bb1a6e32e811decfc09b895
|
7
|
+
data.tar.gz: 808140c38fdd77cfd396811ada2ff2e2e376b899b817a1689692d2790c92e3b8ea2e82ab7f695778cd330703a50135c91a9ce7a7fa3dc9ef0208907443e36de0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0] - 2018-06-12
|
10
|
+
### Added
|
11
|
+
- `before_fork` and `after_fork` hooks
|
12
|
+
|
13
|
+
|
14
|
+
## 0.1.0 - 2018-06-11
|
15
|
+
### Added
|
16
|
+
- A gem to group Rake multitask output by task
|
17
|
+
|
18
|
+
|
19
|
+
[Unreleased]: https://github.com/haines/rake-multilogs/compare/v0.2.0...HEAD
|
20
|
+
[0.2.0]: https://github.com/haines/rake-multilogs/compare/v0.1.0...v0.2.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,23 @@ Add this line to your application's Rakefile:
|
|
43
43
|
require "rake/multilogs"
|
44
44
|
```
|
45
45
|
|
46
|
+
Your multitasks will now run concurrently in forked processes, with each task's output displayed after all tasks have completed.
|
47
|
+
|
48
|
+
The use of forking rather than the default threading implementation means that database connections and other resources need to be handled carefully.
|
49
|
+
You need to make sure each forked process has its own connection by using the `before_fork` and `after_fork` hooks.
|
50
|
+
|
51
|
+
For example, with Active Record, you can put the following config in your Rakefile:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Rake::Multilogs.before_fork do
|
55
|
+
ActiveRecord::Base.connection.disconnect!
|
56
|
+
end
|
57
|
+
|
58
|
+
Rake::Multilogs.after_fork do
|
59
|
+
ActiveRecord::Base.establish_connection
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
46
63
|
|
47
64
|
## Development
|
48
65
|
|
data/Rakefile
CHANGED
data/lib/rake/multilogs.rb
CHANGED
@@ -14,6 +14,49 @@ module Rake
|
|
14
14
|
#
|
15
15
|
# This requires `Process.fork`, so is not supported on JRuby or Windows.
|
16
16
|
module Multilogs
|
17
|
+
class << self
|
18
|
+
# Register a block to be called from the multitask before running its
|
19
|
+
# prerequisites. This is called from the parent process before forking,
|
20
|
+
# and will receive the multitask as a parameter.
|
21
|
+
#
|
22
|
+
# @example Handling database connections with Active Record
|
23
|
+
# Rake::Multilogs.before_fork do
|
24
|
+
# ActiveRecord::Base.connection.disconnect!
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @param block [#to_proc] the block to call (must accept zero or one parameters)
|
28
|
+
# @return [void]
|
29
|
+
def before_fork(&block)
|
30
|
+
@before_fork = block
|
31
|
+
end
|
32
|
+
|
33
|
+
# Register a block to be called before executing a task. This is called
|
34
|
+
# from the child processes after forking, and from the parent process
|
35
|
+
# after the prerequisites have completed and the child processes have
|
36
|
+
# exited. In each case it will receive the task that is about to execute
|
37
|
+
# as a parameter.
|
38
|
+
#
|
39
|
+
# @example Handling database connections with Active Record
|
40
|
+
# Rake::Multilogs.after_fork do
|
41
|
+
# ActiveRecord::Base.establish_connection
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# @param block [#to_proc] the block to call (must accept zero or one parameters)
|
45
|
+
# @return [void]
|
46
|
+
def after_fork(&block)
|
47
|
+
@after_fork = block
|
48
|
+
end
|
49
|
+
|
50
|
+
# @private
|
51
|
+
def call_before_fork(task)
|
52
|
+
@before_fork&.call(task)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @private
|
56
|
+
def call_after_fork(task)
|
57
|
+
@after_fork&.call(task)
|
58
|
+
end
|
59
|
+
end
|
17
60
|
end
|
18
61
|
end
|
19
62
|
|
data/lib/rake/multilogs/fork.rb
CHANGED
data/lib/rake/multilogs/task.rb
CHANGED
@@ -9,11 +9,15 @@ module Rake
|
|
9
9
|
# task and displaying it when all tasks have completed.
|
10
10
|
# @return [void]
|
11
11
|
def invoke_prerequisites_concurrently(task_args, invocation_chain)
|
12
|
+
Multilogs.call_before_fork self
|
13
|
+
|
12
14
|
Forks.new(
|
13
15
|
tasks: prerequisite_tasks,
|
14
16
|
args: task_args,
|
15
17
|
invocation_chain: invocation_chain
|
16
18
|
).invoke
|
19
|
+
|
20
|
+
Multilogs.call_after_fork self
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-multilogs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Haines
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- ".ruby-version"
|
123
123
|
- ".travis.yml"
|
124
124
|
- ".yardopts"
|
125
|
+
- CHANGELOG.md
|
125
126
|
- CODE_OF_CONDUCT.md
|
126
127
|
- Gemfile
|
127
128
|
- Gemfile.lock
|