dwf 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -10
- data/dwf.gemspec +1 -1
- data/lib/dwf/item.rb +8 -2
- data/lib/dwf/worker.rb +1 -1
- data/lib/dwf/workflow.rb +20 -6
- metadata +1 -2
- data/dwf-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0057d6d96f647afa204d1ece11e64444df31b3db21c6ceda3ac92ac73c134105
|
4
|
+
data.tar.gz: f7f1aff90493a9396a7bf13f9e7f6a3c348e32022e73e907ef8571b89c70efd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9207d683e57e95e8fd3e555c2a589fb4be793a8a4cafc479e2446fdd1ab3e180b72154b4c4b8f93aca92bd06159ec8eb3df448ffce0b742bd647ec723088ef4d
|
7
|
+
data.tar.gz: 41fdfb04643bdba4e7afda031308c19a347762aebc281fd42ac7f4be6be5d932a8a2fb610d38276338c07ac0b2835e3e12585796b7d39266e3a97976a39a4e7c
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
# Installation
|
5
5
|
```ruby
|
6
|
-
gem 'dwf', '~> 0.1.
|
6
|
+
gem 'dwf', '~> 0.1.2'
|
7
7
|
```
|
8
8
|
# Execute flow
|
9
9
|
## Declare jobs
|
@@ -15,14 +15,10 @@ class A < Dwf::Item
|
|
15
15
|
def perform
|
16
16
|
puts "#{self.class.name} Working"
|
17
17
|
sleep 2
|
18
|
+
puts params
|
18
19
|
puts "#{self.class.name} Finished"
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
-
class E < A; end
|
23
|
-
class B < A; end
|
24
|
-
class C < E; end
|
25
|
-
class D < E; end
|
26
22
|
```
|
27
23
|
|
28
24
|
## Declare flow
|
@@ -34,11 +30,15 @@ class TestWf < Dwf::Workflow
|
|
34
30
|
run A
|
35
31
|
run B, after: A
|
36
32
|
run C, after: A
|
37
|
-
run E, after: [B, C]
|
38
|
-
run D, after: [E]
|
33
|
+
run E, after: [B, C], params: 'E say hello'
|
34
|
+
run D, after: [E], params: 'D say hello'
|
35
|
+
run F, params: 'F say hello'
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
39
|
+
wf = TestWf.create
|
40
|
+
wf.start!
|
41
|
+
|
42
42
|
```
|
43
43
|
|
44
44
|
### Execute flow
|
@@ -50,17 +50,30 @@ wf.start!
|
|
50
50
|
### Output
|
51
51
|
```
|
52
52
|
A Working
|
53
|
+
F Working
|
53
54
|
A Finished
|
54
|
-
|
55
|
+
F say hello
|
56
|
+
F Finished
|
55
57
|
C Working
|
56
|
-
B
|
58
|
+
B Working
|
57
59
|
C Finished
|
60
|
+
B Finished
|
58
61
|
E Working
|
62
|
+
E say hello
|
59
63
|
E Finished
|
60
64
|
D Working
|
65
|
+
D say hello
|
61
66
|
D Finished
|
62
67
|
```
|
63
68
|
|
69
|
+
# Todo
|
70
|
+
- [x] Make it work
|
71
|
+
- [x] Support pass params
|
72
|
+
- [ ] Support with build-in callback
|
73
|
+
- [ ] Test
|
74
|
+
- [ ] Add github workflow
|
75
|
+
- [ ] Transfer output through each node
|
76
|
+
|
64
77
|
# References
|
65
78
|
- https://github.com/chaps-io/gush
|
66
79
|
- https://github.com/mperham/sidekiq
|
data/dwf.gemspec
CHANGED
data/lib/dwf/item.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'client'
|
|
3
3
|
module Dwf
|
4
4
|
class Item
|
5
5
|
attr_reader :workflow_id, :id, :params, :queue, :klass, :started_at,
|
6
|
-
:enqueued_at, :finished_at, :failed_at
|
6
|
+
:enqueued_at, :finished_at, :failed_at, :callback_type
|
7
7
|
attr_accessor :incomming, :outgoing
|
8
8
|
|
9
9
|
def initialize(options = {})
|
@@ -17,6 +17,7 @@ module Dwf
|
|
17
17
|
@finished_at = options[:finished_at]
|
18
18
|
@enqueued_at = options[:enqueued_at]
|
19
19
|
@started_at = options[:started_at]
|
20
|
+
@callback_type = options[:callback_type]
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.from_hash(hash)
|
@@ -31,6 +32,10 @@ module Dwf
|
|
31
32
|
|
32
33
|
def perform; end
|
33
34
|
|
35
|
+
def cb_build_in?
|
36
|
+
callback_type == Dwf::Workflow::BUILD_IN
|
37
|
+
end
|
38
|
+
|
34
39
|
def perform_async
|
35
40
|
Dwf::Worker.set(queue: queue).perform_async(workflow_id, name)
|
36
41
|
end
|
@@ -132,7 +137,8 @@ module Dwf
|
|
132
137
|
started_at: started_at,
|
133
138
|
failed_at: failed_at,
|
134
139
|
params: params,
|
135
|
-
workflow_id: workflow_id
|
140
|
+
workflow_id: workflow_id,
|
141
|
+
callback_type: callback_type
|
136
142
|
}
|
137
143
|
end
|
138
144
|
|
data/lib/dwf/worker.rb
CHANGED
data/lib/dwf/workflow.rb
CHANGED
@@ -1,32 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'client'
|
2
4
|
require_relative 'worker'
|
3
5
|
require_relative 'callback'
|
4
6
|
|
5
7
|
module Dwf
|
6
8
|
class Workflow
|
7
|
-
|
9
|
+
CALLBACK_TYPES = [
|
10
|
+
BUILD_IN = 'build-in',
|
11
|
+
SK_BATCH = 'sk-batch'
|
12
|
+
].freeze
|
13
|
+
attr_reader :dependencies, :jobs, :started_at, :finished_at, :persisted, :stopped,
|
14
|
+
:callback_type
|
8
15
|
|
9
16
|
class << self
|
10
|
-
def create
|
11
|
-
flow = new
|
17
|
+
def create(*args)
|
18
|
+
flow = new(*args)
|
12
19
|
flow.save
|
13
20
|
flow
|
14
21
|
end
|
15
22
|
end
|
16
23
|
|
17
|
-
def initialize
|
24
|
+
def initialize(options = {})
|
18
25
|
@dependencies = []
|
19
26
|
@id = id
|
20
27
|
@jobs = []
|
21
28
|
@persisted = false
|
22
29
|
@stopped = false
|
30
|
+
@callback_type = options[:callback_type] || BUILD_IN
|
23
31
|
|
24
32
|
setup
|
25
33
|
end
|
26
34
|
|
27
35
|
def start!
|
28
36
|
initial_jobs.each do |job|
|
29
|
-
Dwf::Callback.new.start(job)
|
37
|
+
cb_build_in? ? job.persist_and_perform_async! : Dwf::Callback.new.start(job)
|
30
38
|
end
|
31
39
|
end
|
32
40
|
|
@@ -37,6 +45,10 @@ module Dwf
|
|
37
45
|
true
|
38
46
|
end
|
39
47
|
|
48
|
+
def cb_build_in?
|
49
|
+
callback_type == BUILD_IN
|
50
|
+
end
|
51
|
+
|
40
52
|
def id
|
41
53
|
@id ||= client.build_workflow_id
|
42
54
|
end
|
@@ -49,6 +61,7 @@ module Dwf
|
|
49
61
|
id: client.build_job_id(id, klass.to_s),
|
50
62
|
params: options.fetch(:params, {}),
|
51
63
|
queue: options[:queue],
|
64
|
+
callback_type: callback_type
|
52
65
|
)
|
53
66
|
|
54
67
|
jobs << node
|
@@ -81,7 +94,8 @@ module Dwf
|
|
81
94
|
status: status,
|
82
95
|
stopped: stopped,
|
83
96
|
started_at: started_at,
|
84
|
-
finished_at: finished_at
|
97
|
+
finished_at: finished_at,
|
98
|
+
callback_type: callback_type
|
85
99
|
}
|
86
100
|
end
|
87
101
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dwf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dthtien
|
@@ -78,7 +78,6 @@ files:
|
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
81
|
-
- dwf-0.1.0.gem
|
82
81
|
- dwf.gemspec
|
83
82
|
- lib/dwf.rb
|
84
83
|
- lib/dwf/callback.rb
|
data/dwf-0.1.0.gem
DELETED
Binary file
|