Sha256: f8eb315c23781103b6094ec3056e9366095446572fc9d35bc4d3a750f67d3977

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'grape'

module Cellect
  module Server
    class API < Grape::API
      format :json

      require 'cellect/server/api/helpers'
      require 'cellect/server/api/sets'
      require 'cellect/server/api/users'

      # GET /stats
      # 
      # Provides system load information
      get :stats do
        node_set = Cellect::Server.node_set.actors.first
        usage = ->(keyword) do
          `ps axo #{ keyword }`.chomp.split("\n")[1..-1].collect(&:to_f).inject :+
        end

        {
          memory: usage.call('%mem'),
          cpu: usage.call('%cpu'),
          node_set: { id: node_set.id, ready: node_set.ready? },
          status: Cellect::Server.adapter.status.merge({
            workflows_ready: Cellect::Server.ready?,
            workflows: Workflow.all.map(&:status)
          })
        }
      end

      resources :workflows do

        # GET /workflows
        # 
        # Returns a list of available workflows
        get do
          Cellect::Server.adapter.workflow_list
        end

        segment '/:workflow_id' do
          helpers Helpers
          mount Sets
          mount Users

          # GET /workflows/:workflow_id/status
          # 
          # Returns the workflow's status
          get :status do
            return four_oh_four unless workflow
            workflow.status
          end

          # POST /workflows/:workflow_id/reload
          # 
          # Reloads the workflow from the adapter
          post :reload do
            return four_oh_four unless workflow
            workflow.async.load_data
          end

          # DELETE /workflows/:workflow_id
          # 
          # Not implemented
          delete do
            # delete a workflow (maybe?)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cellect-server-1.3.3 lib/cellect/server/api.rb
cellect-server-1.3.2 lib/cellect/server/api.rb