Application Management

JavaScript

Restart and Shutdown

The Application Management API is accessible through glue.appManager.

See the JavaScript Application Management example on GitHub.

To restart Glue42 Enterprise, use the restart() method. This will close all running applications and their instances and then restart Glue42 Enterprise:

await glue.appManager.restart();

To shut down Glue42 Enterprise, use the exit() method. This will close all running applications and their instances:

await glue.appManager.exit();

Listing Applications

To see a list of all applications available to the current user, use the applications() method:

const applications = glue.appManager.applications();

Specific Application

To get a reference to a specific application, use the application() method and pass the name of the application as an argument:

const app = glue.appManager.application("ClientList");

Current Application Instance

To get a reference to the instance of the current application, use the myInstance property:

const myInstance = glue.appManager.myInstance;

Starting Applications

To start an application, use the start() method of the application object:

const app = glue.appManager.application("ClientList");

const appInstance = await app.start();

The start() method accepts two optional parameters - a context object (object in which you can pass custom data to your app) and an ApplicationStartOptions object:

const app = glue.appManager.application("ClientList");
const context = { selectedUser: 2 };
const startOptions = { hidden: true };

const appInstance = await app.start(context, startOptions);

Listing Running Instances

To list all running instances of all applications, use the instances() method:

// Returns a collection of the running instances of all apps.
glue.appManager.instances();

Stopping Instances

To stop a running instance, use the stop() method of an instance object:

await appInstance.stop();

Events

Shutdown Event

The shutdown event provided by the Application Management API allows you to execute custom code before Glue42 Enterprise shuts down. The available time for the execution of your code is 60 seconds. The callback you provide for handling the event will receive an object with only one property (restarting) as an argument. Use it to determine whether Glue42 Enterprise is restarting or is shutting down.

// The async code in the handler will be awaited up to 60 seconds
// before Glue42 Enterprise shuts down.
const handler = async (args) => {
    const isRestarting = args.restarting;

    if (isRestarting) {
        console.log("Restarting...");
    } else {
        await handleShutdown();
    };
};

glue.appManager.onShuttingDown(handler);

Application Events

The set of applications defined for the current user can be changed at runtime. To track the events which fire when an application has been added, removed or updated, use the respective methods exposed by the Application Management API.

Application added event:

const handler = application => console.log(application.name);

// Notifies you when an application has been added.
const unsubscribe = glue.appManager.onAppAdded(handler);

Application removed event:

const handler = application => console.log(application.name);

// Notifies you when an application has been removed.
const unsubscribe = glue.appManager.onAppRemoved(handler);

Application updated event:

const handler = application => console.log(application.name);

// Notifies you when an application configuratino has been updated.
const unsubscribe = glue.appManager.onAppChanged(handler);

Instance Events

To monitor instance related events globally (for all instances of all applications running in Glue42 Enterprise) or on an application level (only instances of a specific application), use the respective methods exposed by the Application Management API.

Global

The AppManager object offers methods which you can use to monitor instance events for all applications running in Glue42 Enterprise. Get notified when an application instance has started, stopped, has been updated or when starting an application instance has failed. The methods for handling instance events receive a callback as a parameter which in turn receives the application instance as an argument. All methods return an unsubscribe function - use it to stop receiving notifications about instance events.

Instance started event:

const handler = instance => console.log(instance.id);

const unsubscribe = glue.appManager.onInstanceStarted(handler);

Instance stopped event:

const handler = instance => console.log(instance.id);

const unsubscribe = glue.appManager.onInstanceStopped(handler);

Instance updated event:

const handler = instance => console.log(instance.id);

const unsubscribe = glue.appManager.onInstanceUpdated(handler);

Application Level

To monitor instance events on an application level, use the methods offered by the Application object. The methods for handling instance events receive a callback as a parameter which in turn receives the application instance as an argument.

Instance started event:

const app = glue.appManager.application("ClientList");
const handler = instance => console.log(instance.id);

app.onInstanceStarted(handler);

Instance stopped event:

const app = glue.appManager.application("ClientList");
const handler = instance => console.log(instance.id);

app.onInstanceStopped(handler);

Reference

Reference