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
@@ -1,53 +0,0 @@
1
- module Abid
2
- module PlayCore
3
- def set(name, value = nil, &block)
4
- var = :"@#{name}"
5
-
6
- define_method(name) do
7
- unless instance_variable_defined?(var)
8
- if !value.nil?
9
- instance_variable_set(var, value)
10
- elsif block_given?
11
- instance_variable_set(var, instance_eval(&block))
12
- end
13
- end
14
- instance_variable_get(var)
15
- end
16
- end
17
-
18
- def params_spec
19
- @params_spec ||= {}
20
- end
21
-
22
- def param(name, **param_spec)
23
- define_method(name) { task.params[name] }
24
- params_spec[name] = { significant: true }.merge(param_spec)
25
- end
26
-
27
- def undef_param(name)
28
- params_spec.delete(name)
29
- undef_method(name) if method_defined?(name)
30
- end
31
-
32
- def include(*mod)
33
- ms = mod.map do |m|
34
- if m.is_a? Module
35
- m
36
- else
37
- mixin_task = task.application[m, task.scope]
38
-
39
- fail "#{m} is not a mixin" unless mixin_task.is_a? MixinTask
40
-
41
- mixin_task.mixin.tap do |mixin|
42
- # inherit params_spec
43
- mixin.params_spec.each do |k, v|
44
- params_spec[k] ||= v
45
- end
46
- end
47
- end
48
- end
49
-
50
- super(*ms)
51
- end
52
- end
53
- end
@@ -1,41 +0,0 @@
1
- module Abid
2
- module RakeExtensions
3
- module Task
4
- def volatile?
5
- true
6
- end
7
-
8
- def worker
9
- :default
10
- end
11
-
12
- def job
13
- Job[name, defined?(params) ? params : {}]
14
- end
15
-
16
- def params
17
- {}
18
- end
19
-
20
- def name_with_params
21
- name
22
- end
23
-
24
- def concerned?
25
- true
26
- end
27
-
28
- def top_level?
29
- application.top_level_tasks.any? { |t| application[t] == self }
30
- end
31
-
32
- def hooks
33
- @hooks ||= Hash.new { |h, k| h[k] = [] }
34
- end
35
-
36
- def call_hooks(tag, *args)
37
- hooks[tag].each { |h| h.call(*args) }
38
- end
39
- end
40
- end
41
- end
@@ -1,40 +0,0 @@
1
- require 'sequel/plugins/serialization'
2
- require 'abid/state_manager/state'
3
- require 'abid/state_manager/state_proxy'
4
-
5
- module Abid
6
- module StateManager
7
- class Database
8
- Sequel.extension :migration
9
-
10
- MIGRATIONS_PATH = File.expand_path('../../../../migrations', __FILE__)
11
-
12
- # Creates a new database object and checks schema version.
13
- #
14
- # @return [Sequel::Database] database object
15
- # @see Sequel.connect
16
- def self.connect(*args)
17
- db = Sequel.connect(*args)
18
- Sequel::Migrator.check_current(db, MIGRATIONS_PATH)
19
- db
20
- rescue Sequel::Migrator::NotCurrentError
21
- raise Error, 'current schema is out of date'
22
- end
23
-
24
- def initialize(env)
25
- @env = env
26
- @mon = Monitor.new
27
- end
28
-
29
- def connection
30
- @connection ||= self.class.connect(@env.config.database)
31
- end
32
-
33
- def states
34
- @mon.synchronize do
35
- @states ||= Class.new(State.Model(connection[:states]))
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,65 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Abid
4
- module StateManager
5
- # StateProxy provides accessor methods to State for Job#state.
6
- #
7
- # StateProxy holds a reference to the job, and find corresponding state
8
- # every time when needed.
9
- #
10
- # Use StateProxy#find if you have to access the undergrounding State object
11
- # many times.
12
- class StateProxy
13
- def initialize(job)
14
- @job = job
15
- @states = job.env.db.states
16
- end
17
-
18
- # Find underlying State object
19
- #
20
- # @return [State] state corresponding the job.
21
- def find
22
- if @job.volatile?
23
- @states.init_by_job(@job).tap(&:freeze)
24
- else
25
- @states.find_or_init_by_job(@job).tap(&:freeze)
26
- end
27
- end
28
- alias instance find
29
-
30
- # Update the state to started unless volatile.
31
- # @see State.start
32
- def start
33
- return if @job.dryrun? || @job.volatile?
34
- @states.start(@job)
35
- end
36
-
37
- # Try to update the state to started unless volatile.
38
- # @see State.start
39
- # @return [Boolean] false if already running
40
- def try_start
41
- start
42
- true
43
- rescue AlreadyRunningError
44
- false
45
- end
46
-
47
- # Update the state to SUCCESSED / FAILED unless volatile.
48
- # @see State.finish
49
- def finish(error = nil)
50
- return if @job.dryrun? || @job.volatile?
51
- @states.finish(@job, error)
52
- end
53
-
54
- def assume(force: false)
55
- @states.assume(@job, force: force)
56
- end
57
-
58
- # for testing
59
- def mock_fail(error)
60
- start
61
- finish(error)
62
- end
63
- end
64
- end
65
- end
data/lib/abid/task.rb DELETED
@@ -1,123 +0,0 @@
1
- module Abid
2
- class Task < Rake::Task
3
- extend Forwardable
4
-
5
- attr_accessor :play_class_definition, :extends
6
- attr_reader :play, :params
7
-
8
- def_delegators :play, :worker, :volatile?
9
-
10
- def initialize(task_name, app)
11
- super(task_name, app)
12
- @siblings = {}
13
- end
14
-
15
- def play_class
16
- return @play_class if @play_class
17
-
18
- task = self
19
- klass = application.lookup_play_class(extends, scope)
20
- @play_class = Class.new(klass) do |c|
21
- c.task = task
22
- c.class_eval(&task.play_class_definition)
23
- end
24
- end
25
-
26
- def bound?
27
- !@play.nil?
28
- end
29
-
30
- def bind(**params)
31
- fail 'already bound' if bound?
32
-
33
- parsed_params = ParamsParser.parse(params, play_class.params_spec)
34
- return @siblings[parsed_params] if @siblings.include?(parsed_params)
35
-
36
- sorted_params = parsed_params.sort.to_h
37
- sorted_params.freeze
38
-
39
- @siblings[sorted_params] = dup.tap do |t|
40
- t.instance_eval do
41
- @prerequisites = []
42
- @params = sorted_params
43
- @play = play_class.new(t)
44
- call_play_hooks(:setup)
45
- bind_play_hooks(:before, :before_execute)
46
- bind_play_hooks(:after, :after_invoke)
47
- end
48
- end
49
- end
50
-
51
- def prerequisite_tasks
52
- fail 'no play is bound yet' unless bound?
53
-
54
- prerequisites.map do |pre, params|
55
- application[pre, @scope, **self.params.merge(params)]
56
- end
57
- end
58
-
59
- # Name of task with argument list description.
60
- def name_with_args # :nodoc:
61
- if params_description
62
- "#{super} #{params_description}"
63
- else
64
- super
65
- end
66
- end
67
-
68
- # Name of task with params
69
- def name_with_params # :nodoc:
70
- if params_description
71
- "#{name} #{params_description}"
72
- else
73
- super
74
- end
75
- end
76
-
77
- def params_description
78
- sig_params = play_class.params_spec.select do |_, spec|
79
- spec[:significant]
80
- end
81
- return if sig_params.empty?
82
-
83
- if bound? # unbound
84
- p = sig_params.map { |name, _| "#{name}=#{params[name]}" }
85
- else
86
- p = sig_params.map { |name, spec| "#{name}:#{spec[:type]}" }
87
- end
88
-
89
- p.join(' ')
90
- end
91
-
92
- # Execute the play associated with this task.
93
- def execute(_args = nil)
94
- fail 'no play is bound yet' unless bound?
95
-
96
- if application.options.dryrun
97
- application.trace "** Execute (dry run) #{name_with_params}"
98
- return
99
- end
100
- if application.options.trace
101
- application.trace "** Execute #{name_with_params}"
102
- end
103
-
104
- play.run
105
- end
106
-
107
- def bind_play_hooks(tag, to = nil)
108
- to ||= tag
109
- hooks[to] = [proc { |*args| call_play_hooks(tag, *args) }]
110
- end
111
-
112
- def call_play_hooks(tag, *args)
113
- return unless bound?
114
- play_class.hooks[tag].each { |blk| play.instance_exec(*args, &blk) }
115
- end
116
-
117
- class <<self
118
- def define_play(*args, &block) # :nodoc:
119
- Abid.application.define_play(self, *args, &block)
120
- end
121
- end
122
- end
123
- end
@@ -1,61 +0,0 @@
1
- module Abid
2
- module TaskManager
3
- def initialize
4
- super
5
- end
6
-
7
- def define_play(task_class, play_name, extends: nil, &block)
8
- define_task(task_class, play_name).tap do |task|
9
- task.extends = extends
10
- task.play_class_definition = block
11
- end
12
- end
13
-
14
- def define_mixin(task_class, mixin_name, &block)
15
- define_task(task_class, mixin_name).tap do |task|
16
- task.mixin_definition = block
17
- end
18
- end
19
-
20
- def [](task_name, scopes = nil, **params)
21
- task = super(task_name, scopes)
22
-
23
- if task.respond_to? :bind
24
- task.bind(**params)
25
- else
26
- task
27
- end
28
- end
29
-
30
- def play_base(&block)
31
- if block_given?
32
- @play_base = Class.new(Abid::Play, &block)
33
- else
34
- @play_base ||= Abid::Play
35
- end
36
- end
37
-
38
- def lookup_play_class(task_name, scope = nil)
39
- if task_name.nil?
40
- play_base
41
- elsif task_name.is_a? Class
42
- task_name
43
- else
44
- t = lookup(task_name.to_s, scope)
45
- if t.respond_to? :play_class
46
- t.play_class
47
- elsif t.nil?
48
- fail "play #{task_name} not found"
49
- else
50
- fail "task #{task_name} has no play class"
51
- end
52
- end
53
- end
54
-
55
- class << self
56
- def record_task_metadata # :nodoc:
57
- Rake::TaskManager.record_task_metadata
58
- end
59
- end
60
- end
61
- end