chores_kit 0.2.4 → 0.2.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/bin/chores +15 -0
- data/chores_kit.gemspec +1 -2
- data/examples/rubygems.rb +42 -0
- data/lib/chores_kit.rb +2 -2
- data/lib/chores_kit/chore.rb +5 -2
- data/lib/chores_kit/{dag → chore}/dag.rb +7 -5
- data/lib/chores_kit/chore/task.rb +19 -0
- data/lib/chores_kit/chores.rb +23 -1
- data/lib/chores_kit/executors/shell.rb +29 -0
- data/lib/chores_kit/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 898c280b6ba9f1f1941b188b33063553c00361f133b771d6aaa7d23b6bce38e6
|
4
|
+
data.tar.gz: 1e50353fb4cdf45b6d997cee856fd8805ded75c11d30d7e6e65dd0c8bf3bfee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1b9d31c713f4139776773da148968d6a2130d1f80c10430d97f7dd6bd638a481b9a9cd67f403498b5d1b4d12744debbdf734a997596cd9c2af2b47d8754fa6
|
7
|
+
data.tar.gz: bf1d11e5a66d39b7bd73caf3373e574373ba3f82ed21ed100ee8f6d3f6628d7471a9cb09ae0d0ce6f3570ca3c09ac58283c7c2307a45ecc63d1d2cc8894249bb
|
data/Gemfile.lock
CHANGED
data/bin/chores
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'chores_kit'
|
6
|
+
|
7
|
+
filename = ARGV[0]
|
8
|
+
|
9
|
+
unless filename
|
10
|
+
puts 'Error: Expecting filename to run passed as parameter'
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
chore = Chores.load(filename)
|
15
|
+
chore.run!
|
data/chores_kit.gemspec
CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
16
|
f.match(%r{^(test|spec|features)/})
|
17
17
|
end
|
18
|
-
spec.
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.executables << 'chores'
|
20
19
|
spec.require_paths = ['lib']
|
21
20
|
|
22
21
|
spec.required_ruby_version = '>= 2.2.0'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
Chores.define :rubygems do
|
4
|
+
schedule at: '2018-03-12', every: 1.week
|
5
|
+
|
6
|
+
task :download do
|
7
|
+
uri = URI('https://s3-us-west-2.amazonaws.com/rubygems-dumps/?prefix=production/public_postgresql')
|
8
|
+
index = Net::HTTP.get(uri)
|
9
|
+
|
10
|
+
matches = index.match(/.*<Key>(.*)<\/Key>.*/)
|
11
|
+
filename = matches.captures.first
|
12
|
+
url = "https://s3-us-west-2.amazonaws.com/rubygems-dumps/#{filename}"
|
13
|
+
|
14
|
+
sh "curl -o rubygems.tar -L #{url}"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :drop_db do
|
18
|
+
sh 'dropdb -U postgres --if-exists rubygems'
|
19
|
+
end
|
20
|
+
|
21
|
+
task :create_db do
|
22
|
+
sh 'createdb -U postgres rubygems'
|
23
|
+
end
|
24
|
+
|
25
|
+
task :create_extension do
|
26
|
+
sh 'psql -q -U postgres -d rubygems -c "CREATE EXTENSION IF NOT EXISTS hstore;"'
|
27
|
+
end
|
28
|
+
|
29
|
+
task :unpack do
|
30
|
+
sh 'tar xOf rubygems.tar public_postgresql/databases/PostgreSQL.sql.gz | gunzip > rubygems.sql'
|
31
|
+
end
|
32
|
+
|
33
|
+
task :load do
|
34
|
+
sh 'psql -U postgres -d rubygems < rubygems.sql'
|
35
|
+
end
|
36
|
+
|
37
|
+
run :download, triggers: :drop_db
|
38
|
+
run :drop_db, triggers: :create_db
|
39
|
+
run :create_db, triggers: :create_extension
|
40
|
+
run :create_extension, triggers: :unpack
|
41
|
+
run :unpack, triggers: :load
|
42
|
+
end
|
data/lib/chores_kit.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'chores_kit/dag/dag'
|
2
|
-
|
3
1
|
require 'chores_kit/chore'
|
2
|
+
require 'chores_kit/chore/dag'
|
4
3
|
require 'chores_kit/chore/embedded_task'
|
5
4
|
require 'chores_kit/chore/notification'
|
6
5
|
require 'chores_kit/chore/task'
|
6
|
+
require 'chores_kit/executors/shell'
|
7
7
|
require 'chores_kit/definition_proxy'
|
8
8
|
require 'chores_kit/chores'
|
9
9
|
require 'chores_kit/version'
|
data/lib/chores_kit/chore.rb
CHANGED
@@ -83,7 +83,7 @@ module ChoresKit
|
|
83
83
|
# Set explicit root task and skip further processing if the Chore has
|
84
84
|
# just one task defined or if only one of its tasks is set to run
|
85
85
|
if tasks.one? || from == to
|
86
|
-
@dag.root
|
86
|
+
@dag.root!(@dag.find_by(name: from))
|
87
87
|
return
|
88
88
|
end
|
89
89
|
|
@@ -91,7 +91,6 @@ module ChoresKit
|
|
91
91
|
v2 = @dag.vertices.detect { |vertex| vertex[:name] == to }
|
92
92
|
|
93
93
|
@dag.add_edge(from: v1, to: v2)
|
94
|
-
@dag.root = v1
|
95
94
|
end
|
96
95
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
97
96
|
|
@@ -109,5 +108,9 @@ module ChoresKit
|
|
109
108
|
@notifications[condition] = notification
|
110
109
|
end
|
111
110
|
end
|
111
|
+
|
112
|
+
def run!
|
113
|
+
@dag.root.run
|
114
|
+
end
|
112
115
|
end
|
113
116
|
end
|
@@ -3,15 +3,17 @@ require 'dag'
|
|
3
3
|
module ChoresKit
|
4
4
|
class DAG < ::DAG
|
5
5
|
def root
|
6
|
-
@
|
7
|
-
end
|
6
|
+
return @vertices.first if @root.nil? && @edges.empty?
|
8
7
|
|
9
|
-
|
10
|
-
@vertices.detect { |v| v.name == name }
|
8
|
+
@root || @vertices.detect { |v| v.ancestors.empty? && v.successors.any? }
|
11
9
|
end
|
12
10
|
|
13
|
-
def root
|
11
|
+
def root!(vertex)
|
14
12
|
@root = vertex
|
15
13
|
end
|
14
|
+
|
15
|
+
def find_by(name:)
|
16
|
+
@vertices.detect { |v| v.name == name }
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
1
3
|
module ChoresKit
|
2
4
|
class Task
|
3
5
|
attr_reader :name
|
@@ -7,8 +9,25 @@ module ChoresKit
|
|
7
9
|
@args = args
|
8
10
|
end
|
9
11
|
|
12
|
+
def run
|
13
|
+
raise "Task doesn't have any executors" if @callable.nil?
|
14
|
+
|
15
|
+
puts "Running #{@callable.friendly_name} executor with command #{@callable.command} at #{Time.now}"
|
16
|
+
|
17
|
+
duration = Benchmark.realtime do
|
18
|
+
@callable.run!
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Took #{Integer(duration * 1000)}ms to run\n\n"
|
22
|
+
end
|
23
|
+
|
10
24
|
# rubocop:disable Style/MethodMissing
|
11
25
|
def method_missing(name, *args)
|
26
|
+
attributes = { callable: args, callee: self }
|
27
|
+
|
28
|
+
if name == :sh
|
29
|
+
@callable = Executors::Shell.new(name, attributes)
|
30
|
+
end
|
12
31
|
end
|
13
32
|
# rubocop:enable Style/MethodMissing
|
14
33
|
end
|
data/lib/chores_kit/chores.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
|
-
|
1
|
+
class Chores
|
2
|
+
attr_reader :chore
|
3
|
+
|
2
4
|
def self.define(name, &block)
|
3
5
|
proxy = ChoresKit::DefinitionProxy.new(name)
|
4
6
|
proxy.instance_eval(&block) if block_given?
|
5
7
|
proxy.chore
|
6
8
|
end
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
@chore = instance_eval(File.read(filename))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load(filename)
|
15
|
+
new(filename).chore
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load_all
|
19
|
+
tasks = Pathname.glob('tasks/**/*.rb')
|
20
|
+
|
21
|
+
tasks.each do |task_file|
|
22
|
+
load(Pathname.pwd + task_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
@chore.run!
|
28
|
+
end
|
7
29
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module ChoresKit
|
4
|
+
module Executors
|
5
|
+
class Shell
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize(name, attributes)
|
9
|
+
@name = name
|
10
|
+
@callee = attributes.fetch(:callee)
|
11
|
+
@callable = attributes.fetch(:callable)
|
12
|
+
end
|
13
|
+
|
14
|
+
def friendly_name
|
15
|
+
'Shell'
|
16
|
+
end
|
17
|
+
|
18
|
+
def command
|
19
|
+
@callable.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def run!
|
23
|
+
output, status = Open3.capture2e(*@callable)
|
24
|
+
|
25
|
+
raise "Running #{friendly_name} '#{@callable}' failed with status #{status.exitstatus}. Error message: #{output}" unless status.success?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/chores_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chores_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lennard Timm
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: as-duration
|
@@ -111,7 +111,8 @@ dependencies:
|
|
111
111
|
description:
|
112
112
|
email:
|
113
113
|
- hi@lenn4rd.io
|
114
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- chores
|
115
116
|
extensions: []
|
116
117
|
extra_rdoc_files: []
|
117
118
|
files:
|
@@ -124,20 +125,23 @@ files:
|
|
124
125
|
- LICENSE.txt
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
128
|
+
- bin/chores
|
127
129
|
- bin/console
|
128
130
|
- bin/rake
|
129
131
|
- bin/rspec
|
130
132
|
- bin/rubocop
|
131
133
|
- bin/setup
|
132
134
|
- chores_kit.gemspec
|
135
|
+
- examples/rubygems.rb
|
133
136
|
- lib/chores_kit.rb
|
134
137
|
- lib/chores_kit/chore.rb
|
138
|
+
- lib/chores_kit/chore/dag.rb
|
135
139
|
- lib/chores_kit/chore/embedded_task.rb
|
136
140
|
- lib/chores_kit/chore/notification.rb
|
137
141
|
- lib/chores_kit/chore/task.rb
|
138
142
|
- lib/chores_kit/chores.rb
|
139
|
-
- lib/chores_kit/dag/dag.rb
|
140
143
|
- lib/chores_kit/definition_proxy.rb
|
144
|
+
- lib/chores_kit/executors/shell.rb
|
141
145
|
- lib/chores_kit/version.rb
|
142
146
|
homepage: https://github.com/lenn4rd/chores_kit
|
143
147
|
licenses:
|