Commands

Once you are connected, you can start sending commands.

Every command has the following properties:

  • cmd

    CommandTypeenum

    mandatory

    The command name.

  • id
    int mandatory

    Unique id of the command.


The response always has the following properties:

  • id
    int

    The same id that was provided in request.

  • success
    bool

    On success it will be set to true.

  • errCode

    ErrorCodeenum

    On failure, success will be set to false and errCode will contain an error code.

As you can see you can identify the response by the id.

Sending requests and handling responses

  let requestMap = {};
  let socket = null;

  function SendCommand(aCommand) {
    // Generate command id.
    aCommand.id = Math.floor(Math.random() * 100000);

    // Send command.
    socket.send(JSON.stringify(aCommand));

    // Add command to request map.
    requestMap[aCommand.id] = {};
    promise = new Promise((resolve, reject) => {
      requestMap[aCommand.id].resolveCb = resolve;
      requestMap[aCommand.id].rejectCb = reject;
    });
    requestMap[aCommand.id].promise = promise;

    // Return promise.
    return promise;
  }

  function onOpen(aEvent) {
    console.log('Connected.');

    const cmd = {
      cmd: 'cmdListJobs'
    };
    SendCommand(cmd).then(data => {
      // TODO: Handle data.jobs...
    });
  }

  function onMessage(aEvent) {
    data = JSON.parse(aEvent.data);

    if (data.id) {
      // Handle response.
      if (data.id in requestMap) {
        // Trigger success or failure callback.
        if (data.success)
          requestMap[data.id].resolveCb(data);
        else
          requestMap[data.id].rejectCb(data);

        // Delete request from the map.
        delete requestMap[data.id];
      }
    } else {
      // TODO: Handle events.
    }
  }

Here is the list of commands:

cmdAddJob

Creates a new job and adds it to the queue.

    Request parameters

  • config
    Configuration

    Configuration data group object.

    Please note that the configuration you provide here will overwrite the default settings and remain in effect until it is changed again.

  • input
    Input mandatory

    Input data group object.

  • allowOverstock
    bool def: false

    The allowOverstock parameter controls the behavior of the cutting optimization algorithm. When set to true, the algorithm is permitted to allocate more stock items than currently available. This can be useful in scenarios where future stock replenishment is anticipated or over-allocation is acceptable. Please note that enabling this option may lead to situations where demand exceeds supply.

    Note that it applies only to standard stock sizes. So, in order to use more stock items than available, you have to define standard stock items in material definition. Then, you have to add stock item with the same standard size.

  • bestSolutionCriterion

    BestSolutionCriterionenum

    def: optimal

    The bestSolutionCriterion parameter allows you to choose the criterion for selecting the best solution. Thanks to this, the algorithms know what the optimization goal is.

    Response parameters

  • jobId
    int mandatory

    ID of the new job.


cmdListJobs

You can use the cmdListJobs command to get a list of jobs.

The list will show you all the jobs, no matter if they are finished, waiting or in process.

A job is in process when it is currently being optimized.

The cmdListJobs command does not have any additional request parameters.

    Response parameters

  • jobs
    list(object)

    Contains list of all the job.
    Each job is described by an object with the following properties.

    Show Child Attributes


cmdRemoveJob

The cmdRemoveJob allows to remove specified job.

Request parameters

  • jobId
    int mandatory

    ID of the job to be removed.

The cmdRemoveJob response does not have any additional parameters.


cmdGetJobInfo

The cmdGetJobInfo command returns all information about the specified job.

Request parameters

  • jobId
    int mandatory

    ID of the job to get information about.

Response parameters

  • state

    JobStateenum

    State of the job.

  • errorCode

    ErrorCodeenum

    If the job state is set to sError, then errorCode CustomProperty contains the error code.

  • errorDescription
    string

    Additional error information.

  • progress
    float

    Optimization progress in percent, so 100 means 100%.

  • combinationCount
    int

    Number of combinations checked.

  • createDate
    date

    Date of the job creation.

  • startDate
    date

    Date when the job optimization started.

  • endDate
    date

    Date when job optimization ended.

  • result
    Output

    Results of the optimization in a form of Output data group object.


cmdGetStatus

The cmdGetStatus command returns current server status.

The cmdGetStatus command does not have any additional request parameters.

Response parameters

  • status

    Statusenum

    The status of the server.

  • activeJob
    object

    Provides information about currently optimized job.

    Show Child Attributes

  • queueSize
    int

    The queue size, not including the active job.

Websocket Commands

function start() {
  $('#bAddJob').on('click', event => {
    const cmd = {
      cmd: 'cmdAddJob',
      config: config,
      input: input
    };
    SendCommand(cmd);
  });

  $('#bRefresh').on('click', event => {
    const cmd = {
      cmd: 'cmdListJobs'
    };
    SendCommand(cmd).then(data => {
      $('#ulJobs').empty();
      for (let i = 0; i < data.jobs.length; i++) {
        let job = data.jobs[i];

        if (job.state == 'sPending')
          activeJobId = job.id;

        let stateHtml;
        if (job.state == 'sError')
          stateHtml = `${job.state}, ${job.errorCode}, ${job.errorDescription}`;
        else
          stateHtml = job.state;

        let jobEl = $(`#job-${job.id}`);
        if (jobEl.length == 0)
          $('#ulJobs').append(`<li id="job-${job.id}">Job ${job.id}
                               <span className='clsState'>${stateHtml}</span>
                               <span className='clsProgress'>${job.progress.toFixed(2) + '%'}</span></li>`);
        else
          jobEl.replace(`<li id="job-${job.id}">Job ${job.id}
                         <span className='clsState'>${stateHtml}</span>
                         <span className='clsProgress'>${job.progress.toFixed(2) + '%'}</span></li>`);

        const cmd = {
          cmd: 'cmdGetJobInfo',
          jobId: job.id
        };
        SendCommand(cmd).then(data => {
          // TODO: do something with results if available.
        });
      }
    });
  });

  $('#bCancel').on('click', event => {
    const cmd = {
      cmd: 'cmdRemoveJob',
      jobId: activeJobId
    };
    SendCommand(cmd);
  });
}