AutoPush Class

Beta

Use AutoPush to automatically push local changes to a specified IModel. To do this, create an AutoPush object, specifying the IModelDb that should be monitored. The instance registers itself to react to events and timers. Often, backend will start auto-pushing when an IModelDb is opened for read-write.

Example:

    IModelDb.onOpened.addListener((_requestContext: AuthorizedClientRequestContext, iModel: IModelDb) => {
        if (iModel.openParams.openMode !== OpenMode.ReadWrite)
            return;

        // Setting a concurrency control policy is an example of something you might do in an onOpened event handler.
        iModel.concurrencyControl.setPolicy(new ConcurrencyControl.OptimisticPolicy());
    });

A service or agent would normally get its AutoPushParams parameters from data provided at deployment time. For example, a service might read configuration data from a .json file that is deployed with the service.

{
   "autoPush": {
     "pushIntervalSecondsMin": ${MYSERVICE-AUTOPUSH-INTERVAL-MIN},
     "pushIntervalSecondsMax": ${MYSERVICE-AUTOPUSH-INTERVAL-MAX},
     "autoSchedule": true
   },
}

Note that the values of some of the configuration property values are defined by placeholders denoted by ${some-macro-name}. These placeholders are to be replaced by EnvMacroSubst.replaceInProperties with the values of environment values of the same names. These environment variables would typically be set by the deployment mechanism from deployment parameters.

The service would read the configuration like this:

export function readConfigParams(): any {
    const config = require("./MyService.config.json");

    const defaultConfigValues: any = {
        /* ... define a property corresponding to each placeholder in the config file and a default value for it ... */
        "some-macro-name": "its-default-value",
    };

    // Replace ${some-macro-name} placeholders with actual environment variables,
    // falling back on the supplied default values.
    EnvMacroSubst.replaceInProperties(config, true, defaultConfigValues);

    return config;
}

Methods

Name Description
constructor(iModel: IModelDb, params: AutoPushParams, activityMonitor?: AppActivityMonitor): AutoPush Construct an AutoPushManager.  
cancel(): void Cancel the next auto-push.  
reserveCodes(): Promise<void>    
scheduleNextAutoPushIfNecessary(): void    
scheduleNextPush(intervalSeconds?: number): void Schedules an auto-push.  
validateAutoPushParams(params: any): void Static Check that 'params' is a valid AutoPushParams object.  

Properties

Name Type Description
autoSchedule Accessor boolean The autoSchedule property  
durationOfLastPushMillis Accessor ReadOnly number The length of time in milliseconds that the last push required to finish.  
endOfLastPushMillis Accessor ReadOnly number The time that the last push finished in unix milliseconds.  
event BeEvent<AutoPushEventHandler> Events raised by AutoPush.  
iModel Accessor ReadOnly IModelDb The IModelDb that this is auto-pushing.  
lastError Accessor ReadOnly any | undefined The last push error, if any.  
state Accessor ReadOnly AutoPushState Check the current state of this AutoPush.  

Defined in

Last Updated: 13 May, 2019