Class: Peplum::Application

Inherits:
Cuboid::Application
  • Object
show all
Defined in:
lib/peplum/application.rb,
lib/peplum/application/peers.rb,
lib/peplum/application/services/scheduler.rb,
lib/peplum/application/services/shared_hash.rb

Defined Under Namespace

Modules: Services Classes: Error, Peers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



31
32
33
34
35
# File 'lib/peplum/application.rb', line 31

def initialize(*)
  super

  @peers = Peers.new
end

Instance Attribute Details

#peersObject (readonly)

Returns the value of attribute peers.



29
30
31
# File 'lib/peplum/application.rb', line 29

def peers
  @peers
end

Class Method Details

.inherited(application) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/peplum/application.rb', line 16

def inherited( application )
  super

  Cuboid::Application.application = application

  application.validate_options_with :validate_options
  application.serialize_with JSON

  application.instance_service_for :scheduler,   Services::Scheduler
  application.instance_service_for :shared_hash, Services::SharedHash
end

Instance Method Details

#payloadObject

This method is abstract.

Implements:

* `.run` -- Worker; executes its payload against `objects`.
* `.group` -- Splits given `objects` into groups for each worker.
* `.merge` -- Merges results from multiple workers.

That’s all we need to turn any application into a super version of itself.



64
65
66
# File 'lib/peplum/application.rb', line 64

def payload
  fail Error, 'Missing payload app!'
end

#report(data) ⇒ Object



68
69
70
# File 'lib/peplum/application.rb', line 68

def report( data )
  super payload.merge( data )
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/peplum/application.rb', line 37

def run
  Raktr.global.on_error do |_, e|
    $stderr.puts e
  end

  options = @options.dup
  peplum_options = options.delete( 'peplum' )
  payload_options = options.delete( 'payload' )

  # We have a master so we're not the scheduler, run the payload.
  if peplum_options['master']
    execute( peplum_options, payload_options )

  # We're the scheduler Instance, get to grouping and spawning.
  else
    schedule( peplum_options, payload_options )
  end
end