Class: Bumbleworks::Process

Inherits:
Object
  • Object
show all
Includes:
WorkitemEntityStorage
Defined in:
lib/bumbleworks/process.rb,
lib/bumbleworks/process/error_record.rb

Defined Under Namespace

Classes: EntityConflict, ErrorRecord

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WorkitemEntityStorage

#wrapped_workitem

Constructor Details

#initialize(wfid) ⇒ Process

Returns a new instance of Process.



32
33
34
# File 'lib/bumbleworks/process.rb', line 32

def initialize(wfid)
  @id = wfid
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/bumbleworks/process.rb', line 157

def method_missing(method, *args)
  ps = process_status
  if ps.respond_to?(method)
    return ps.send(method, *args)
  end
  super
end

Instance Attribute Details

#idObject (readonly) Also known as: wfid

Returns the value of attribute id.



10
11
12
# File 'lib/bumbleworks/process.rb', line 10

def id
  @id
end

Class Method Details

.all(options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/bumbleworks/process.rb', line 13

def all(options = {})
  ids(options).map do |wfid|
    new(wfid)
  end
end

.countObject



27
28
29
# File 'lib/bumbleworks/process.rb', line 27

def count
  ids.count
end

.ids(options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/bumbleworks/process.rb', line 19

def ids(options = {})
  wfids = Bumbleworks.dashboard.process_wfids
  wfids.reverse! if options[:reverse]
  limit = options[:limit] || wfids.count
  offset = options[:offset] || 0
  wfids[offset, limit]
end

Instance Method Details

#<=>(other) ⇒ Object



49
50
51
52
53
54
# File 'lib/bumbleworks/process.rb', line 49

def <=>(other)
  unless other.is_a?(self.class)
    raise ArgumentError, "comparison of Bumbleworks::Process with #{other.class} failed"
  end
  wfid <=> other.wfid
end

#==(other) ⇒ Object



56
57
58
59
# File 'lib/bumbleworks/process.rb', line 56

def ==(other)
  return false unless other.is_a?(self.class)
  wfid == other.wfid
end

#all_subscribed_tagsObject



121
122
123
124
125
126
127
128
129
130
# File 'lib/bumbleworks/process.rb', line 121

def all_subscribed_tags
  @all_subscribed_tags ||= trackers.inject({ :global => [] }) do |memo, t|
    if t.global?
      memo[:global].concat t.tags
    else
      (memo[t.wfid] ||= []).concat t.tags
    end
    memo
  end
end

#cancel!Object



144
145
146
# File 'lib/bumbleworks/process.rb', line 144

def cancel!
  Bumbleworks.cancel_process!(wfid)
end

#definition_nameObject



152
153
154
155
# File 'lib/bumbleworks/process.rb', line 152

def definition_name
  root_ruote_expression.attribute('name') ||
    root_ruote_expression.attribute_text
end

#entity_storage_workitemObject



69
70
71
# File 'lib/bumbleworks/process.rb', line 69

def entity_storage_workitem
  super(entity_workitem)
end

#entity_workitemObject



61
62
63
64
65
66
67
# File 'lib/bumbleworks/process.rb', line 61

def entity_workitem
  @entity_workitem ||= if workitems.map(&:entity_fields).uniq.length <= 1
    workitems.first
  else
    raise EntityConflict
  end
end

#errorsObject



83
84
85
86
87
88
89
# File 'lib/bumbleworks/process.rb', line 83

def errors
  @errors ||= Bumbleworks.dashboard.context.storage.get_many('errors', [wfid]).map { |err|
    Bumbleworks::Process::ErrorRecord.new(
      ::Ruote::ProcessError.new(err)
    )
  }
end

#expression_at_position(position) ⇒ Object



79
80
81
# File 'lib/bumbleworks/process.rb', line 79

def expression_at_position(position)
  expressions.detect { |exp| exp.expid == position }
end

#expressionsObject



73
74
75
76
77
# File 'lib/bumbleworks/process.rb', line 73

def expressions
  @expressions ||= ruote_expressions.map { |rexp|
    Bumbleworks::Expression.new(rexp)
  }
end

#is_waiting_for?(event) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/bumbleworks/process.rb', line 136

def is_waiting_for?(event)
  subscribed_events.include? event.to_s
end

#kill!Object



140
141
142
# File 'lib/bumbleworks/process.rb', line 140

def kill!
  Bumbleworks.kill_process!(wfid)
end

#leavesObject



91
92
93
94
95
96
97
# File 'lib/bumbleworks/process.rb', line 91

def leaves
  @leaves ||= ruote_expressions.inject([]) { |a, exp|
    a.select { |e| ! exp.ancestor?(e.fei) } + [ exp ]
  }.map { |leaf|
    Bumbleworks::Expression.new(leaf)
  }
end

#process_statusObject



148
149
150
# File 'lib/bumbleworks/process.rb', line 148

def process_status
  @process_status ||= Bumbleworks.dashboard.process(id)
end

#reloadObject



36
37
38
39
40
41
# File 'lib/bumbleworks/process.rb', line 36

def reload
  (instance_variables - [:@id]).each do |memo|
    instance_variable_set(memo, nil)
  end
  self
end

#running?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/bumbleworks/process.rb', line 43

def running?
  !process_status.nil?
end

#schedulesObject



115
116
117
118
119
# File 'lib/bumbleworks/process.rb', line 115

def schedules
  @schedules ||= Bumbleworks.dashboard.schedules(id).map { |schedule_hash|
    Bumbleworks::Schedule.new(schedule_hash)
  }
end

#subscribed_eventsObject



132
133
134
# File 'lib/bumbleworks/process.rb', line 132

def subscribed_events
  all_subscribed_tags[:global]
end

#tasksObject



103
104
105
# File 'lib/bumbleworks/process.rb', line 103

def tasks
  @tasks ||= Bumbleworks::Task.for_process(wfid)
end

#trackersObject



107
108
109
110
111
112
113
# File 'lib/bumbleworks/process.rb', line 107

def trackers
  @trackers ||= Bumbleworks.dashboard.get_trackers.select { |tid, attrs|
    attrs['msg']['fei'] && attrs['msg']['fei']['wfid'] == id
  }.map { |tid, original_hash|
    Bumbleworks::Tracker.new(tid, original_hash)
  }
end

#workitemsObject



99
100
101
# File 'lib/bumbleworks/process.rb', line 99

def workitems
  @workitems ||= leaves.map(&:workitem)
end