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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64d4859313b42953886395d47fc659c685bcac240fcc1cdf7629152be7cfcca5
4
- data.tar.gz: f7da7f6086547bb179bd5e1210b5d3f8ddb3fe8423855969aa8536b6b2412062
3
+ metadata.gz: b6f75135ee16d2687d59a5a8b7e4fd6f51e605641780e954616c1baacf43691f
4
+ data.tar.gz: 5d86280f61247d95e3f2404ad196c63b9895dc6be16103fa456f4dcd1098e8ca
5
5
  SHA512:
6
- metadata.gz: 04f34a77107f34c4dce60865f260f8e154b3c805f719c67f4c496fbfd23cb3eadec8dd10ede8ee4d8c4f6cffdc545a2848127e7b950e5d6645abf8bb21ccead2
7
- data.tar.gz: 07bb9c6bdafa949605454cb953b29d23d4e5edd3b6bf0befc63628afc3b72bd12d540b08725483d5dbe0231ca22c765dee8ef40d5a17040bc0a21718265e226c
6
+ metadata.gz: 9d9613373228fc4b73f4279285a081781fec14fd165a2fd6c5944e05364bcd8f0bf6c41f04bd64146291f7a410f17086a74e55436bb1a6e32e811decfc09b895
7
+ data.tar.gz: 808140c38fdd77cfd396811ada2ff2e2e376b899b817a1689692d2790c92e3b8ea2e82ab7f695778cd330703a50135c91a9ce7a7fa3dc9ef0208907443e36de0
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake-multilogs (0.1.0)
4
+ rake-multilogs (0.2.0)
5
5
  rake (~> 12.1)
6
6
 
7
7
  GEM
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
@@ -13,6 +13,7 @@ RuboCop::RakeTask.new
13
13
 
14
14
  desc "Generate documentation"
15
15
  YARD::Rake::YardocTask.new :doc
16
+ CLEAN << ".yardoc/"
16
17
  CLOBBER << "doc/"
17
18
 
18
19
  task :default => [:doc, :rubocop, :test]
@@ -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
 
@@ -41,6 +41,7 @@ module Rake
41
41
  end
42
42
 
43
43
  @task.application.standard_exception_handling do
44
+ Multilogs.call_after_fork @task
44
45
  @task.send :invoke_with_call_chain, @args, @invocation_chain
45
46
  end
46
47
  end
@@ -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
@@ -3,6 +3,6 @@
3
3
  module Rake
4
4
  module Multilogs
5
5
  # Current version of the rake-multilogs gem.
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  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.1.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 00:00:00.000000000 Z
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