Refresh a Public Variable Graph Template

Public variables are useful to hold java script objects that are created from business logic to be used multiple times throughout a graph. Persistent public variables may require their values to be refreshed from time to time - e.g. the appParams public variable. The public variable is typically initialised/ refreshed at the start of the graph. Refresh frequencies are set in the appParams variable. appParams also follows this process closely.

The public variable will be loaded on first use and they will only be refreshed if the last refresh was more than the number of minutes specified in the 'appParams.{your public variable}_ExpiryMinutes' public variable. If no refresh value is present in appParms, the public variable will be persisted indefinitely. This graph is a generalisation of the Refresh Application Parameters graph and shares some content. 

Package contents

  • Graph: publicVariableRefresh 
  • Requires appParams public variable to be present.

Setup 

Create your persistent public variable with default value 'notSetYet':

If I wanted to store the refresh rate for appParams as 10 minutes, I would put the following data in the appParams table: 

INSERT INTO `appParams`
(`paramKey`,
`paramValue`,
`paramType`,
`description`)
VALUES
('{yourPublicVariableName}_ExpiryMinutes',
'10',
'number',
'Refresh public variable after this number of minutes'
);


paramKeyparamValueparamTypedescription
appParams_ExpiryMinutes10string
Refresh public variable after this number of minutes

Create a subgraph that initialises the public variable - i.e. if the values are stored in a database table then you would have a subgraph that reads from the DB table into the public variable.

Using  

  • Ensure appParams exists and has been initialised before running this public variable refresh & refresh rate is included in the appParams table
  • Create a new item from the Refresh Public Variable graph template and place near the start of your graph

  • Update the first Get node to reference your public variable. This tests whether the PV has been initialised yet
    • If it is not set yet then it will go straight to the business logic to set it's value - (this graph assumes the default value of the PV is 'notSetSet')
    • If the PV is populated then it will run the decidePublicVariableRefresh script to determine whether enough time has passed since the PV was last refreshed
  • Set the arguments on the decidePublicVariableRefresh script - pvName, location of the public variable, appParams
    • This script tests the PV last refresh timestamp (stored in pvInfo public variable) was X minutes ago
  • Create the business logic to set the value of the public variable
  • Set the arguments of the setPublicVariableLastRefreshTs which stores the last refresh timestamp into the pvInfo public variable

Privacy Policy
© 2022 CSG International, Inc.