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



153
154
155
156
157
158
159
# File 'lib/bumbleworks/process.rb', line 153

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
# File 'lib/bumbleworks/process.rb', line 49

def <=>(other)
  wfid <=> other.wfid
end

#==(other) ⇒ Object



53
54
55
# File 'lib/bumbleworks/process.rb', line 53

def ==(other)
  wfid == other.wfid
end

#all_subscribed_tagsObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/bumbleworks/process.rb', line 117

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



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

def cancel!
  Bumbleworks.cancel_process!(wfid)
end

#definition_nameObject



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

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

#entity_storage_workitemObject



65
66
67
# File 'lib/bumbleworks/process.rb', line 65

def entity_storage_workitem
  super(entity_workitem)
end

#entity_workitemObject



57
58
59
60
61
62
63
# File 'lib/bumbleworks/process.rb', line 57

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

#errorsObject



79
80
81
82
83
84
85
# File 'lib/bumbleworks/process.rb', line 79

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



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

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

#expressionsObject



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

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

#is_waiting_for?(event) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#kill!Object



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

def kill!
  Bumbleworks.kill_process!(wfid)
end

#leavesObject



87
88
89
90
91
92
93
# File 'lib/bumbleworks/process.rb', line 87

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



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

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



111
112
113
114
115
# File 'lib/bumbleworks/process.rb', line 111

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

#subscribed_eventsObject



128
129
130
# File 'lib/bumbleworks/process.rb', line 128

def subscribed_events
  all_subscribed_tags[:global]
end

#tasksObject



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

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

#trackersObject



103
104
105
106
107
108
109
# File 'lib/bumbleworks/process.rb', line 103

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



95
96
97
# File 'lib/bumbleworks/process.rb', line 95

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