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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ffde33a5c57e9528172a4ba0b75c1a9cbaca30e62fd5ebe0028cad69e5590b9
4
- data.tar.gz: ab123ae6de59a28fe8c99a886ec7299adde7ded2121e55719465aef7ff2c7af2
3
+ metadata.gz: a2894dd7dff299d2cb4f2c9bf67b7be01f27adc93cfc7729fbbac8c3c9988722
4
+ data.tar.gz: ce6d91fc194a7441557bd3250f994b65dbb35dd29d7adbb0a08c3be699a88cf8
5
5
  SHA512:
6
- metadata.gz: e96b0c486602044964eb01fafb82ac329d8ca779f70e85d01781a8605e13e141e5e14bdc443e0ce64bbdfed5bf6502f1ca7e77d50bb82afa68d5523e135e1558
7
- data.tar.gz: e02b283810944d41e23ba4c96d8380f7f0a1a5799615d7c73c264af251b6447f9b1ea925bd6cfb790f53c55269b3728480efc0231ee89ce19121800c72955648
6
+ metadata.gz: 37ff1a501b2661b0a63d9d0c3844d323952e07e05135661169138dd3ee88f906115c3db13b33205dbcc7faf94af6ac2dc4a8cc2e2e49982789ca5e75cca0ea2a
7
+ data.tar.gz: 5cc7c495ca3b2463ef2d8d168f0bb43f73c6c7d7a970d66b21ebe22068db389e272819e2d2f7bb49c6fc2835f6b22a8b3991421e5501dc763a94c5aecd5aca88
@@ -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)
@@ -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
@@ -0,0 +1,13 @@
1
+ require 'pallets'
2
+
3
+ class Anonymous < Pallets::Task
4
+ def run
5
+ puts 'This is anonymous!'
6
+ end
7
+ end
8
+
9
+ workflow = Pallets::Workflow.build do
10
+ task 'Anonymous'
11
+ end
12
+
13
+ workflow.new.run
@@ -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(task_class, dependencies)
18
+ graph.add(as, dependencies)
17
19
 
18
- task_config[task_class] = {
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
  }
@@ -9,15 +9,19 @@ module Pallets
9
9
  end
10
10
 
11
11
  def add(node, dependencies)
12
- @nodes[node] = dependencies
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
- @nodes[node]
20
+ nodes[node]
17
21
  end
18
22
 
19
23
  def empty?
20
- @nodes.empty?
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
- @nodes.each_key(&block)
47
+ nodes.each_key(&block)
42
48
  end
43
49
 
44
50
  def tsort_each_child(node, &block)
45
- @nodes.fetch(node).each(&block)
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
@@ -1,3 +1,3 @@
1
1
  module Pallets
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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 |task_class, order|
29
- job = serializer.dump(construct_job(task_class))
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(task_class)
35
- {}.tap do |job|
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.merge(self.class.task_config[task_class])
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.5.1
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-06-01 00:00:00.000000000 Z
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