Class: Bumbleworks::Process

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

Defined Under Namespace

Classes: EntityConflict

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.



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

def initialize(wfid)
  @id = wfid
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/bumbleworks/process.rb', line 127

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.



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

def id
  @id
end

Class Method Details

.allObject



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

def all
  ids.map do |wfid|
    new(wfid)
  end
end

.countObject



22
23
24
# File 'lib/bumbleworks/process.rb', line 22

def count
  ids.count
end

.idsObject



18
19
20
# File 'lib/bumbleworks/process.rb', line 18

def ids
  Bumbleworks.dashboard.process_wfids
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
# File 'lib/bumbleworks/process.rb', line 40

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

#all_subscribed_tagsObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/bumbleworks/process.rb', line 96

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



119
120
121
# File 'lib/bumbleworks/process.rb', line 119

def cancel!
  Bumbleworks.cancel_process!(wfid)
end

#entity_storage_workitemObject



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

def entity_storage_workitem
  super(entity_workitem)
end

#entity_workitemObject



44
45
46
47
48
49
50
# File 'lib/bumbleworks/process.rb', line 44

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

#errorsObject



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

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

#expressionsObject



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

def expressions
  @expressions ||= begin
    context = Bumbleworks.dashboard.context
    raw_expressions = context.storage.get_many('expressions', [wfid])
    raw_expressions.collect { |e|
      ::Ruote::Exp::FlowExpression.from_h(context, e)
    }.sort_by { |e|
      e.fei.expid
    }
  end
end

#is_waiting_for?(event) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#kill!Object



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

def kill!
  Bumbleworks.kill_process!(wfid)
end

#leavesObject



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

def leaves
  @leaves ||= expressions.inject([]) { |a, exp|
    a.select { |e| ! exp.ancestor?(e.fei) } + [ exp ]
  }
end

#process_statusObject



123
124
125
# File 'lib/bumbleworks/process.rb', line 123

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

#reloadObject



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

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

#subscribed_eventsObject



107
108
109
# File 'lib/bumbleworks/process.rb', line 107

def subscribed_events
  all_subscribed_tags[:global]
end

#tasksObject



84
85
86
# File 'lib/bumbleworks/process.rb', line 84

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

#trackersObject



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

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



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

def workitems
  @workitems ||= leaves.map(&:applied_workitem).map { |wi| Bumbleworks::Workitem.new(wi) }
end