Forge Developer

Beta

Forge Developer

Beta

Rate this page:

Runtime

About

Each time you deploy or invoke code on Forge, your code runs inside the sandbox environment. The runtime properties allow you to configure aspects of your app's environment.

PropertyTypeRequiredDescription
snapshots

boolean

Whether a snapshot of the app is taken at deployment time. Default value of true.

Example

1
2
runtime:
  snapshots: true

Invocation context

The invocation context is a function that gets called on invocation time. Each module receives different request parameters based on the module type.

A code editor showing the invocation context

Limitations

Invocation time

The invocation context has a maximum timeout of 10 seconds. Your function will be stopped and will result in an error if processing exceeds the time limit.

Snapshot context

Snapshot is the mechanism of evaluating your function’s global scope at each deployment of the app, rather than at every invocation. Forge apps use snapshots by default, as this improves the response time for your app. You can disable snapshots, but this means your app needs to be fully evaluated on each invocation. For this reason, you should consider leaving snapshots enabled.

The following image highlights a sample snapshot context. Note that the invocation method is not run at this point in time.

A code editor showing the constants declared in the snapshot context

Reference

The snapshots flag is available under the runtime object with a default value of true.

1
2
3
app:
  runtime:
    snapshots: true # Boolean

Limitations

Environment variables

Environment variables are not available in the snapshot context.

Example

1
2
3
4
5
const myVariable = process.env.MY_VARIABLE;

export const run = () => {
  console.log(myVariable) // Value is undefined
};

Randomness

Random values created at snapshot time are not random on each function invocation.

Example

1
2
3
4
5
const snapshotContextRandom = Math.random();

export const run = () => {
  console.log(snapshotContextRandom); // Same value per invocation
};

Buffers

We discourage using Buffers in the snapshot context. Warnings will be presented at deploy time if this is detected.

1
2
3
4
5
const snapshotContextBuffer = new Buffer(); // May result in unpredictable behavior

export const run = () => {
  // ...
};

Rate this page: