Class: Tengine::Job::Runtime::RootJobnet

Inherits:
Jobnet
  • Object
show all
Defined in:
lib/tengine/job/runtime/root_jobnet.rb

Overview

DSLを評価して登録されるルートジョブネットを表すVertex

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(name, options = {}) ⇒ Object

Tengine::Core::FindByName で定義しているクラスメソッドfind_by_nameを上書きしています



72
73
74
75
# File 'lib/tengine/job/runtime/root_jobnet.rb', line 72

def find_by_name(name, options = {})
  version = options[:version] || Tengine::Core::Setting.dsl_version
  where({:name => name, :dsl_version => version}).first
end

Instance Method Details

#execute(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tengine/job/runtime/root_jobnet.rb', line 11

def execute(options = {})
  event_sender = options.delete(:sender) || Tengine::Event.default_sender
  with(safe: safemode(self.class.collection)).save! if new_record?
  result = Tengine::Job::Runtime::Execution.with(
              safe: safemode(Tengine::Job::Runtime::Execution.collection)
           ).create!(
             (options || {}).update(:root_jobnet_id => self.id)
           )
  event_sender.fire(:"start.execution.job.tengine", :properties => {
      :execution_id => result.id,
      :root_jobnet_id => self.id,
      :target_jobnet_id => self.id
    })
  result
end

#find_duplicationObject



65
66
67
68
# File 'lib/tengine/job/runtime/root_jobnet.rb', line 65

def find_duplication
  return nil unless self.new_record?
  self.class.find_by_name(name, :version => self.dsl_version)
end

#fire_stop_event(options = Hash.new) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tengine/job/runtime/root_jobnet.rb', line 46

def fire_stop_event(options = Hash.new)
  root_jobnet_id = self.id.to_s
  result = Tengine::Job::Runtime::Execution.create!(
    options.merge(:root_jobnet_id => root_jobnet_id))

  EM.run do
    Tengine::Event.fire(:"stop.jobnet.job.tengine",
      :source_name => name_as_resource,
      :properties => {
        :execution_id => result.id.to_s,
        :root_jobnet_id => root_jobnet_id,
        :target_jobnet_id => root_jobnet_id.to_s,
        :stop_reason => "user_stop",
      })
  end

  return result
end

#rerun(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tengine/job/runtime/root_jobnet.rb', line 27

def rerun(*args)
  options = args.extract_options!
  sender = options.delete(:sender) || Tengine::Event.default_sender
  options = options.merge({
      :retry => true,
      :root_jobnet_id => self.id,
    })
  result = Tengine::Job::Runtime::Execution.new(options)
  result.target_actual_ids ||= []
  result.target_actual_ids += args.flatten
  result.with(safe: safemode(Tengine::Job::Runtime::Execution.collection)).save!
  sender.wait_for_connection do
    sender.fire(:'start.execution.job.tengine', :properties => {
        :execution_id => result.id.to_s
      })
  end
  result
end