Class: Bumbleworks::Ruote

Inherits:
Object
  • Object
show all
Defined in:
lib/bumbleworks/ruote.rb

Class Method Summary collapse

Class Method Details

.dashboard(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/bumbleworks/ruote.rb', line 6

def dashboard(options = {})
  @dashboard ||= begin
    context = if options[:start_worker] == true
      ::Ruote::Worker.new(storage)
    else
      storage
    end
    ::Ruote::Dashboard.new(context)
  end
end

.launch(name, *args) ⇒ Object



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

def launch(name, *args)
  dashboard.launch(dashboard.variables[name], *args)
end

.register_participants(&block) ⇒ Object



44
45
46
47
48
# File 'lib/bumbleworks/ruote.rb', line 44

def register_participants(&block)
  dashboard.register(&block) if block
  set_catchall_if_needed
  dashboard.participant_list
end

.reset!Object



70
71
72
73
74
75
76
77
78
# File 'lib/bumbleworks/ruote.rb', line 70

def reset!
  if @storage
    @storage.purge!
    @storage.shutdown
  end
  @dashboard.shutdown if @dashboard && @dashboard.respond_to?(:shutdown)
  @storage = nil
  @dashboard = nil
end

.set_catchall_if_neededObject



50
51
52
53
54
55
56
57
# File 'lib/bumbleworks/ruote.rb', line 50

def set_catchall_if_needed
  last_participant = dashboard.participant_list.last
  unless last_participant && last_participant.regex == "^.+$" &&
      ["Ruote::StorageParticipant", "Bumbleworks::StorageParticipant"].include?(last_participant.classname)
    catchall = ::Ruote::ParticipantEntry.new(["^.+$", ["Bumbleworks::StorageParticipant", {}]])
    dashboard.participant_list = dashboard.participant_list.push(catchall)
  end
end

.start_worker!(options = {}) ⇒ Object

Start a worker, which will begin polling for messages in the workflow storage. You can run multiple workers if you are using a storage that supports them (such as Sequel or Redis, but not Hash) - they all just have to be connected to the same storage, and be able to instantiate participants in the participant list.

Parameters:

  • options (Hash) (defaults to: {})

    startup options for the worker

Options Hash (options):

  • :verbose (Boolean)

    whether or not to spin up a “noisy” worker, which will output all messages picked up

  • :join (Boolean)

    whether or not to join the worker thread; if false, this method will return, and the worker thread will be disconnected, and killed if the calling process exits.



32
33
34
35
36
37
38
# File 'lib/bumbleworks/ruote.rb', line 32

def start_worker!(options = {})
  @dashboard = nil
  dashboard(:start_worker => true)
  dashboard.noisy = options[:verbose] == true
  dashboard.join if options[:join] == true
  dashboard.worker
end

.storageObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/bumbleworks/ruote.rb', line 59

def storage
  @storage ||= begin
    all_adapters = Bumbleworks.configuration.storage_adapters
    adapter = all_adapters.detect do |adapter|
      adapter.use?(Bumbleworks.storage)
    end
    raise UndefinedSetting, "Storage is missing or not supported.  Supported: #{all_adapters.map(&:display_name).join(', ')}" unless adapter
    adapter.driver.new(Bumbleworks.storage)
  end
end