abid 0.3.0.pre.alpha.3 → 0.3.0.pre.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/abid.gemspec +1 -2
  4. data/exe/abidsc +1 -1
  5. data/lib/abid.rb +3 -30
  6. data/lib/abid/application.rb +83 -13
  7. data/lib/abid/cli/assume.rb +7 -8
  8. data/lib/abid/cli/list.rb +2 -2
  9. data/lib/abid/cli/migrate.rb +1 -1
  10. data/lib/abid/cli/revoke.rb +9 -10
  11. data/lib/abid/config.rb +2 -0
  12. data/lib/abid/dsl/abid_job.rb +58 -0
  13. data/lib/abid/dsl/actions.rb +36 -0
  14. data/lib/abid/dsl/job.rb +58 -0
  15. data/lib/abid/dsl/job_manager.rb +53 -0
  16. data/lib/abid/dsl/mixin.rb +52 -0
  17. data/lib/abid/dsl/params_spec.rb +64 -0
  18. data/lib/abid/dsl/play.rb +35 -0
  19. data/lib/abid/dsl/play_core.rb +354 -0
  20. data/lib/abid/dsl/rake_job.rb +41 -0
  21. data/lib/abid/dsl/syntax.rb +34 -0
  22. data/lib/abid/dsl/task.rb +53 -0
  23. data/lib/abid/engine.rb +36 -6
  24. data/lib/abid/engine/executor.rb +30 -48
  25. data/lib/abid/engine/process.rb +102 -68
  26. data/lib/abid/engine/process_manager.rb +72 -28
  27. data/lib/abid/engine/scheduler.rb +24 -30
  28. data/lib/abid/engine/waiter.rb +20 -30
  29. data/lib/abid/engine/worker_manager.rb +26 -60
  30. data/lib/abid/environment.rb +12 -27
  31. data/lib/abid/error.rb +2 -0
  32. data/lib/abid/params_format.rb +29 -12
  33. data/lib/abid/rake_extensions.rb +11 -3
  34. data/lib/abid/state_manager.rb +40 -0
  35. data/lib/abid/state_manager/state.rb +52 -114
  36. data/lib/abid/state_manager/state_service.rb +88 -0
  37. data/lib/abid/status.rb +63 -0
  38. data/lib/abid/version.rb +1 -1
  39. metadata +19 -32
  40. data/lib/Abidfile.rb +0 -1
  41. data/lib/abid/dsl_definition.rb +0 -29
  42. data/lib/abid/job.rb +0 -67
  43. data/lib/abid/job_manager.rb +0 -22
  44. data/lib/abid/mixin_task.rb +0 -29
  45. data/lib/abid/params_parser.rb +0 -50
  46. data/lib/abid/play.rb +0 -66
  47. data/lib/abid/play_core.rb +0 -53
  48. data/lib/abid/rake_extensions/task.rb +0 -41
  49. data/lib/abid/state_manager/database.rb +0 -40
  50. data/lib/abid/state_manager/state_proxy.rb +0 -65
  51. data/lib/abid/task.rb +0 -123
  52. data/lib/abid/task_manager.rb +0 -61
@@ -0,0 +1,63 @@
1
+ require 'concurrent/atomic/atomic_reference'
2
+ require 'concurrent/ivar'
3
+
4
+ module Abid
5
+ class Status
6
+ def initialize(initial_state)
7
+ @state = Concurrent::AtomicReference.new(initial_state)
8
+ @complete = Concurrent::IVar.new
9
+ @observers = []
10
+ end
11
+
12
+ def get
13
+ @state.get
14
+ end
15
+
16
+ def wait(timeout = nil)
17
+ @complete.wait(timeout)
18
+ end
19
+
20
+ def compare_and_set(old_state, new_state, complete = false)
21
+ return false unless @state.compare_and_set(old_state, new_state)
22
+ if complete
23
+ @complete.set([old_state, new_state])
24
+ else
25
+ notify_observers(old_state, new_state)
26
+ end
27
+ true
28
+ end
29
+
30
+ def try_set(new_state, complete = false)
31
+ old_state = @state.get_and_set(new_state)
32
+ if complete
33
+ @complete.try_set([old_state, new_state])
34
+ else
35
+ notify_observers(old_state, new_state)
36
+ end
37
+ new_state
38
+ end
39
+
40
+ def complete?
41
+ @complete.complete?
42
+ end
43
+
44
+ # @yieldparam old_state [Object]
45
+ # @yieldparam new_state [Object]
46
+ def on_complete
47
+ @complete.add_observer do |_time, (old_state, new_state), _reason|
48
+ yield(old_state, new_state)
49
+ end
50
+ end
51
+
52
+ # @yieldparam old_state [Object]
53
+ # @yieldparam new_state [Object]
54
+ def on_update(&block)
55
+ @observers << block
56
+ on_complete(&block)
57
+ end
58
+
59
+ def notify_observers(old_state, new_state)
60
+ @observers.each { |block| block.call(old_state, new_state) }
61
+ end
62
+ end
63
+ end
data/lib/abid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Abid
2
- VERSION = '0.3.0-alpha.3'
2
+ VERSION = '0.3.0-alpha.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre.alpha.3
4
+ version: 0.3.0.pre.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hikaru Ojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,20 +68,6 @@ dependencies:
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '10.0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '10.0'
83
- - !ruby/object:Gem::Dependency
84
- name: concurrent-ruby-ext
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: sequel
84
+ name: concurrent-ruby-ext
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
@@ -109,7 +95,7 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: sqlite3
98
+ name: sequel
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
@@ -123,7 +109,7 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: rbtree
112
+ name: sqlite3
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - ">="
@@ -172,7 +158,6 @@ files:
172
158
  - bin/setup
173
159
  - exe/abid
174
160
  - exe/abidsc
175
- - lib/Abidfile.rb
176
161
  - lib/abid.rb
177
162
  - lib/abid/application.rb
178
163
  - lib/abid/cli.rb
@@ -182,7 +167,17 @@ files:
182
167
  - lib/abid/cli/revoke.rb
183
168
  - lib/abid/cli/table_formatter.rb
184
169
  - lib/abid/config.rb
185
- - lib/abid/dsl_definition.rb
170
+ - lib/abid/dsl/abid_job.rb
171
+ - lib/abid/dsl/actions.rb
172
+ - lib/abid/dsl/job.rb
173
+ - lib/abid/dsl/job_manager.rb
174
+ - lib/abid/dsl/mixin.rb
175
+ - lib/abid/dsl/params_spec.rb
176
+ - lib/abid/dsl/play.rb
177
+ - lib/abid/dsl/play_core.rb
178
+ - lib/abid/dsl/rake_job.rb
179
+ - lib/abid/dsl/syntax.rb
180
+ - lib/abid/dsl/task.rb
186
181
  - lib/abid/engine.rb
187
182
  - lib/abid/engine/executor.rb
188
183
  - lib/abid/engine/process.rb
@@ -192,20 +187,12 @@ files:
192
187
  - lib/abid/engine/worker_manager.rb
193
188
  - lib/abid/environment.rb
194
189
  - lib/abid/error.rb
195
- - lib/abid/job.rb
196
- - lib/abid/job_manager.rb
197
- - lib/abid/mixin_task.rb
198
190
  - lib/abid/params_format.rb
199
- - lib/abid/params_parser.rb
200
- - lib/abid/play.rb
201
- - lib/abid/play_core.rb
202
191
  - lib/abid/rake_extensions.rb
203
- - lib/abid/rake_extensions/task.rb
204
- - lib/abid/state_manager/database.rb
192
+ - lib/abid/state_manager.rb
205
193
  - lib/abid/state_manager/state.rb
206
- - lib/abid/state_manager/state_proxy.rb
207
- - lib/abid/task.rb
208
- - lib/abid/task_manager.rb
194
+ - lib/abid/state_manager/state_service.rb
195
+ - lib/abid/status.rb
209
196
  - lib/abid/version.rb
210
197
  - migrations/01_create_state_table.rb
211
198
  homepage: https://github.com/ojima-h/abid
data/lib/Abidfile.rb DELETED
@@ -1 +0,0 @@
1
- # allows the built-in tasks to load without a abidfile
@@ -1,29 +0,0 @@
1
- module Abid
2
- module DSL
3
- def play(*args, &block)
4
- Abid::Task.define_play(*args, &block)
5
- end
6
-
7
- def define_worker(name, thread_count)
8
- Abid.global.worker_manager.define(name, thread_count)
9
- end
10
-
11
- def play_base(&block)
12
- Abid.application.play_base(&block)
13
- end
14
-
15
- def helpers(*extensions, &block)
16
- Abid::Play.helpers(*extensions, &block)
17
- end
18
-
19
- def invoke(task, *args, **params)
20
- Job.find_by_task(Abid.application[task, **params]).invoke(*args)
21
- end
22
-
23
- def mixin(*args, &block)
24
- Abid::MixinTask.define_mixin(*args, &block)
25
- end
26
- end
27
- end
28
-
29
- extend Abid::DSL
data/lib/abid/job.rb DELETED
@@ -1,67 +0,0 @@
1
- require 'forwardable'
2
- require 'monitor'
3
-
4
- module Abid
5
- # Job is an aggregation object of components around the task.
6
- class Job
7
- attr_reader :name, :params, :env
8
-
9
- class << self
10
- extend Forwardable
11
- def_delegators 'Abid.global.job_manager', :[], :find_by_task
12
- end
13
-
14
- # @!visibility private
15
- def initialize(env, name, params)
16
- @env = env
17
- @name = name
18
- @params = params.sort.to_h.freeze
19
- @mon = Monitor.new
20
- end
21
-
22
- def invoke(*args)
23
- Engine::Scheduler.invoke(self, *args)
24
- process.wait
25
- end
26
-
27
- def params_str
28
- @params_str ||= YAML.dump(params)
29
- end
30
-
31
- def digest
32
- @digest ||= Digest::MD5.hexdigest(name + "\n" + params_str)
33
- end
34
-
35
- def task
36
- @task ||= Abid.application[name, nil, params]
37
- end
38
-
39
- def state
40
- @state ||= StateManager::StateProxy.new(self)
41
- end
42
-
43
- def prerequisites
44
- task.prerequisite_tasks.map do |preq_task|
45
- env.job_manager.find_by_task(preq_task)
46
- end
47
- end
48
-
49
- def process
50
- @mon.synchronize do
51
- @process ||= env.process_manager.create
52
- end
53
- end
54
-
55
- def worker
56
- env.worker_manager[task.worker]
57
- end
58
-
59
- def volatile?
60
- task.volatile? || env.options.disable_state
61
- end
62
-
63
- def dryrun?
64
- env.options.dryrun || env.options.preview
65
- end
66
- end
67
- end
@@ -1,22 +0,0 @@
1
- require 'monitor'
2
-
3
- module Abid
4
- class JobManager
5
- def initialize(env)
6
- @env = env
7
- @cache = {}
8
- @mon = Monitor.new
9
- end
10
-
11
- def [](name, params = {})
12
- @mon.synchronize do
13
- key = [name, params.sort.freeze].freeze
14
- @cache[key] ||= Job.new(@env, name, params)
15
- end
16
- end
17
-
18
- def find_by_task(task)
19
- self[task.name, task.params]
20
- end
21
- end
22
- end
@@ -1,29 +0,0 @@
1
- module Abid
2
- class MixinTask < Rake::Task
3
- class Mixin < Module
4
- include PlayCore
5
- attr_reader :task
6
-
7
- def initialize(task, *args, &block)
8
- @task = task
9
- super(*args, &block)
10
- end
11
- end
12
-
13
- attr_accessor :mixin_definition
14
-
15
- def mixin
16
- @mixin ||= Mixin.new(self, &mixin_definition)
17
- end
18
-
19
- def execute(_args = nil)
20
- raise 'mixin is not executable'
21
- end
22
-
23
- class <<self
24
- def define_mixin(*args, &block) # :nodoc:
25
- Abid.application.define_mixin(self, *args, &block)
26
- end
27
- end
28
- end
29
- end
@@ -1,50 +0,0 @@
1
- module Abid
2
- module ParamsParser
3
- class <<self
4
- def parse(params, specs)
5
- specs.map do |name, spec|
6
- if params.include?(name)
7
- value = type_cast(params[name], spec[:type])
8
- elsif ENV.include?(name.to_s)
9
- value = type_cast(ENV[name.to_s], spec[:type])
10
- elsif spec.key?(:default)
11
- value = spec[:default]
12
- else
13
- fail "param #{name} is not specified"
14
- end
15
-
16
- [name, value]
17
- end.to_h
18
- end
19
-
20
- def type_cast(value, type)
21
- case type
22
- when :boolean then value == true || value == 'true'
23
- when :int then value.to_i
24
- when :float then value.to_f
25
- when :string then value.to_s
26
- when :date then type_cast_date(value)
27
- when :datetime, :time then type_cast_time(value)
28
- when nil then value
29
- else fail "invalid type: #{type}"
30
- end
31
- end
32
-
33
- def type_cast_date(value)
34
- case value
35
- when Date then value
36
- when Time, DateTime then value.to_date
37
- else Date.parse(value.to_s)
38
- end
39
- end
40
-
41
- def type_cast_time(value)
42
- case value
43
- when Date then value.to_time
44
- when Time, DateTime then value
45
- else Time.parse(value.to_s)
46
- end
47
- end
48
- end
49
- end
50
- end
data/lib/abid/play.rb DELETED
@@ -1,66 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Abid
4
- class Play
5
- extend PlayCore
6
-
7
- class << self
8
- attr_accessor :task
9
-
10
- def inherited(child)
11
- params_spec.each { |k, v| child.params_spec[k] = v.dup }
12
- hooks.each { |k, v| child.hooks[k] = v.dup }
13
- end
14
-
15
- def hooks
16
- @hooks ||= Hash.new { |h, k| h[k] = [] }
17
- end
18
-
19
- def helpers(*extensions, &block)
20
- class_eval(&block) if block_given?
21
- include(*extensions) if extensions.any?
22
- end
23
-
24
- def setup(&block)
25
- hooks[:setup] << block
26
- end
27
-
28
- def before(&block)
29
- hooks[:before] << block
30
- end
31
-
32
- def after(&block)
33
- hooks[:after] << block
34
- end
35
-
36
- def method_added(name)
37
- params_spec.delete(name) # undef param
38
- end
39
- end
40
-
41
- set :worker, :default
42
- set :volatile, false
43
-
44
- attr_reader :task
45
-
46
- def initialize(task)
47
- @task = task
48
- end
49
-
50
- def run
51
- # noop
52
- end
53
-
54
- def needs(task_name, **params)
55
- task.enhance([[task_name, params]])
56
- end
57
-
58
- def volatile?
59
- volatile
60
- end
61
-
62
- def preview?
63
- task.application.options.preview
64
- end
65
- end
66
- end