Class: UU::OS::CMD::AsyncCommandController

Inherits:
CommandController show all
Defined in:
uu_os_cmd-server-2.5.1/lib/uu/os/cmd/async_command_controller.rb

Overview

Ancestor for development of asynchronous commands. See documentation of CommandController for basic information.

Method on_exec is always invoked synchronously. It should contain only necessary validation of execution preconditions. If validation passes, invoke_async method should be invoked on execution context which handles asynchronous invocation of on_exec_async method.

Instance Method Summary (collapse)

Methods included from Util::ResponseBuilder

#handle_response, #response, #streamed_response

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UU::OS::Application::AbstractController

Instance Method Details

- (Object) get_context(request)



58
59
60
61
62
# File 'uu_os_cmd-server-2.5.1/lib/uu/os/cmd/async_command_controller.rb', line 58

def get_context(request)
  ctx = super(request)
  ctx.instance_variable_set(:@forbid_async, false) unless ctx.nil?
  return ctx
end

- (Object) on_exec(ctx)

Method containing necessary validations (and other preparation tasks) to be done before asynchronous part of command is invoked.

Parameters:

Returns:

Raises:



29
30
31
32
# File 'uu_os_cmd-server-2.5.1/lib/uu/os/cmd/async_command_controller.rb', line 29

def on_exec(ctx)
  raise UU::OS::CMD::CommandError.new(UU::OS::IPC::ErrorKind::SERVER, UU::OS::IPC::ErrorCodes::NOT_IMPLEMENTED,
    "Method on_exec is not implemented on #{self.class.name}.")
end

- (URI, String) on_exec_async(ctx)

Main action method of asynchronous controller. This method is called asynchronously once invoke_async method on execution context is invoked.

Parameters:

Returns:

  • (URI, String)

    Result of asynchronous method. Currently only URI is supported as return value.

Raises:



41
42
43
44
# File 'uu_os_cmd-server-2.5.1/lib/uu/os/cmd/async_command_controller.rb', line 41

def on_exec_async(ctx)
  raise UU::OS::CMD::CommandError.new(UU::OS::IPC::ErrorKind::SERVER, UU::OS::IPC::ErrorCodes::NOT_IMPLEMENTED,
    "Method on_exec_async is not implemented on #{self.class.name}.")
end

- (Object) on_exec_async_status(ctx)

Method provides actual status of asynchronous task. This can be typically done by invocation of CommandContext#invoke_async_status method on execution context and returning its result.

Parameters:

Returns:

  • (Object)

    Object representing status of asynchronous task.



53
54
55
# File 'uu_os_cmd-server-2.5.1/lib/uu/os/cmd/async_command_controller.rb', line 53

def on_exec_async_status(ctx)
  return ctx.invoke_async_status(ctx.parameters[:taskUri])
end