Class: CloudCrowd::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/cloud_crowd/server.rb

Overview

The main CloudCrowd (Sinatra) application. The actions are:

Admin

get /

Render the admin console, with a progress meter for running jobs.

get /status

Get the combined JSON of every active job and worker.

get /worker/:name

Look up the details of a WorkUnit that a Worker is busy processing.

get /heartbeat

Returns 200 OK to let monitoring tools know the server's up.

Public API

post /jobs

Begin a new Job. Post with a JSON representation of the job-to-be. (see examples).

get /jobs/:job_id

Check the status of a Job. Response includes output, if the Job has finished.

delete /jobs/:job_id

Clean up a Job when you're done downloading the results. Removes all intermediate files.

Internal Workers API

put /node/:host

Registers a new Node, making it available for processing.

delete /node/:host

Removes a Node from the registry, freeing up any WorkUnits that it had checked out.

put /work/:unit_id

Mark a finished WorkUnit as completed or failed, with results.

Constant Summary

DISTRIBUTE_INTERVAL =

The interval (in seconds) at which the server will distribute new work units to the nodes

20

Instance Method Summary (collapse)

Constructor Details

- (Server) initialize(*args)

At initialization record the identity of this Ruby instance as a server.



126
127
128
129
130
# File 'lib/cloud_crowd/server.rb', line 126

def initialize(*args)
  super(*args)
  CloudCrowd.identity = :server
  self.distribute_periodically
end

Instance Method Details

- (Object) distribute_periodically

Perform distribution of work units in a background thread



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/cloud_crowd/server.rb', line 133

def distribute_periodically
  @distribute_thread = Thread.new do
    loop do
      puts "Distributing jobs to nodes"
      begin
        WorkUnit.distribute_to_nodes
      rescue StandardError => e
        puts "Exception: #{e}"
        puts e.backtrace 
      end
      sleep DISTRIBUTE_INTERVAL
    end
  end
end