pallets 0.5.1 → 0.6.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 +5 -0
- data/examples/aliases.rb +28 -0
- data/examples/anonymous.rb +13 -0
- data/lib/pallets/dsl/workflow.rb +6 -3
- data/lib/pallets/graph.rb +11 -5
- data/lib/pallets/version.rb +1 -1
- data/lib/pallets/workflow.rb +16 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2894dd7dff299d2cb4f2c9bf67b7be01f27adc93cfc7729fbbac8c3c9988722
|
4
|
+
data.tar.gz: ce6d91fc194a7441557bd3250f994b65dbb35dd29d7adbb0a08c3be699a88cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ff1a501b2661b0a63d9d0c3844d323952e07e05135661169138dd3ee88f906115c3db13b33205dbcc7faf94af6ac2dc4a8cc2e2e49982789ca5e75cca0ea2a
|
7
|
+
data.tar.gz: 5cc7c495ca3b2463ef2d8d168f0bb43f73c6c7d7a970d66b21ebe22068db389e272819e2d2f7bb49c6fc2835f6b22a8b3991421e5501dc763a94c5aecd5aca88
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.6.0] - 2019-09-02
|
10
|
+
### Added
|
11
|
+
- define task aliases in order to reuse tasks within a workflow definition (#44)
|
12
|
+
- define anonymous workflows (#45)
|
13
|
+
|
9
14
|
## [0.5.1] - 2019-06-01
|
10
15
|
### Changed
|
11
16
|
- fix transaction completeness in Appsignal instrumenter (#43)
|
data/examples/aliases.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'pallets'
|
2
|
+
|
3
|
+
class Aliases < Pallets::Workflow
|
4
|
+
task 'StartSmtpServer'
|
5
|
+
task 'SendEmail', as: 'SayHello', depends_on: 'StartSmtpServer'
|
6
|
+
task 'SendEmail', as: 'SayGoodbye', depends_on: 'StartSmtpServer'
|
7
|
+
task 'StopSmtpServer' => ['SayHello', 'SayGoodbye']
|
8
|
+
end
|
9
|
+
|
10
|
+
class StartSmtpServer < Pallets::Task
|
11
|
+
def run
|
12
|
+
puts "Starting SMTP server..."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class SendEmail < Pallets::Task
|
17
|
+
def run
|
18
|
+
puts "* sending e-mail"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class StopSmtpServer < Pallets::Task
|
23
|
+
def run
|
24
|
+
puts "Stopped SMTP server"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Aliases.new.run
|
data/lib/pallets/dsl/workflow.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Pallets
|
2
2
|
module DSL
|
3
3
|
module Workflow
|
4
|
-
def task(arg, depends_on: nil, max_failures: nil, &block)
|
4
|
+
def task(arg, as: nil, depends_on: nil, max_failures: nil, &block)
|
5
5
|
klass, dependencies = case arg
|
6
6
|
when Hash
|
7
7
|
# The `task Foo => Bar` notation
|
@@ -12,10 +12,13 @@ module Pallets
|
|
12
12
|
end
|
13
13
|
|
14
14
|
task_class = klass.to_s
|
15
|
+
as ||= task_class
|
16
|
+
|
15
17
|
dependencies = Array(dependencies).compact.uniq.map(&:to_s)
|
16
|
-
graph.add(
|
18
|
+
graph.add(as, dependencies)
|
17
19
|
|
18
|
-
task_config[
|
20
|
+
task_config[as] = {
|
21
|
+
'workflow_class' => self.name,
|
19
22
|
'task_class' => task_class,
|
20
23
|
'max_failures' => max_failures || Pallets.configuration.max_failures
|
21
24
|
}
|
data/lib/pallets/graph.rb
CHANGED
@@ -9,15 +9,19 @@ module Pallets
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def add(node, dependencies)
|
12
|
-
|
12
|
+
raise WorkflowError, "Task #{node} is already defined in this workflow. "\
|
13
|
+
"Use `task '#{node}', as: 'FooBar'` to define an "\
|
14
|
+
"alias and reuse task" if nodes.key?(node)
|
15
|
+
|
16
|
+
nodes[node] = dependencies
|
13
17
|
end
|
14
18
|
|
15
19
|
def parents(node)
|
16
|
-
|
20
|
+
nodes[node]
|
17
21
|
end
|
18
22
|
|
19
23
|
def empty?
|
20
|
-
|
24
|
+
nodes.empty?
|
21
25
|
end
|
22
26
|
|
23
27
|
# Returns nodes topologically sorted, together with their order (number of
|
@@ -37,12 +41,14 @@ module Pallets
|
|
37
41
|
|
38
42
|
private
|
39
43
|
|
44
|
+
attr_reader :nodes
|
45
|
+
|
40
46
|
def tsort_each_node(&block)
|
41
|
-
|
47
|
+
nodes.each_key(&block)
|
42
48
|
end
|
43
49
|
|
44
50
|
def tsort_each_child(node, &block)
|
45
|
-
|
51
|
+
nodes.fetch(node).each(&block)
|
46
52
|
rescue KeyError
|
47
53
|
raise WorkflowError, "Task #{node} is marked as a dependency but not defined"
|
48
54
|
end
|
data/lib/pallets/version.rb
CHANGED
data/lib/pallets/workflow.rb
CHANGED
@@ -4,6 +4,12 @@ module Pallets
|
|
4
4
|
|
5
5
|
attr_reader :context
|
6
6
|
|
7
|
+
def self.build(&block)
|
8
|
+
Class.new(self).tap do |workflow_class|
|
9
|
+
workflow_class.instance_eval(&block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
def initialize(context_hash = {})
|
8
14
|
@id = nil
|
9
15
|
# Passed in context hash needs to be buffered
|
@@ -25,19 +31,18 @@ module Pallets
|
|
25
31
|
private
|
26
32
|
|
27
33
|
def jobs_with_order
|
28
|
-
self.class.graph.sorted_with_order.map do |
|
29
|
-
job = serializer.dump(construct_job(
|
34
|
+
self.class.graph.sorted_with_order.map do |task_alias, order|
|
35
|
+
job = serializer.dump(construct_job(task_alias))
|
30
36
|
[order, job]
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
def construct_job(
|
35
|
-
|
40
|
+
def construct_job(task_alias)
|
41
|
+
Hash[self.class.task_config[task_alias]].tap do |job|
|
36
42
|
job['wfid'] = id
|
37
|
-
job['jid'] = "J#{Pallets::Util.generate_id(task_class)}".upcase
|
38
|
-
job['workflow_class'] = self.class.name
|
43
|
+
job['jid'] = "J#{Pallets::Util.generate_id(job['task_class'])}".upcase
|
39
44
|
job['created_at'] = Time.now.to_f
|
40
|
-
end
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
def backend
|
@@ -48,6 +53,10 @@ module Pallets
|
|
48
53
|
Pallets.serializer
|
49
54
|
end
|
50
55
|
|
56
|
+
def self.name
|
57
|
+
@name ||= super || '<Anonymous>'
|
58
|
+
end
|
59
|
+
|
51
60
|
def self.task_config
|
52
61
|
@task_config ||= {}
|
53
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pallets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Horak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- README.md
|
57
57
|
- Rakefile
|
58
58
|
- bin/pallets
|
59
|
+
- examples/aliases.rb
|
60
|
+
- examples/anonymous.rb
|
59
61
|
- examples/appsignal.rb
|
60
62
|
- examples/config/appsignal.yml
|
61
63
|
- examples/config_savvy.rb
|