Information for: DEVELOPERS   PARTNERS

Refresh a public variable graph template

Public variables are useful to hold JavaScript objects created from business logic used various times throughout a graph. Persistent public variables may require their values refresh on occasion—for example, the appParams public variable. The public variable initializes at the start of the graph. Refresh frequencies are set in the appParams variable. The appParams variable also adheres to the following process:

  • The public variable will load on first use, and the variable will only refresh if the last refresh exceeds the number of minutes specified in the appParams.{your public variable}_ExpiryMinutes public variable.
  • If no refresh value is present in appParams, the public variable will persist indefinitely. The 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

  1. Sign in to Acquia Journey.
  2. Create your persistent public variable with the default Initial Value notSetYet.
  3. To store the refresh rate for appParams as 10 minutes, add the following data to the appParams table:
INSERT INTO `appParams`
(`paramKey`,
`paramValue`,
`paramType`,
`description`)
VALUES
('{yourPublicVariableName}_ExpiryMinutes',
'10',
'number',
'Refresh public variable after this number of minutes'
);
paramKey paramValue paramType description
appParams_ExpiryMinutes 10 string Refresh public variable after the specified number of minutes
  • Create a subgraph initializing the public variable—for example, if the values are stored in a database table, then you would have a subgraph reading from the DB table into the public variable.

Using the Refresh a Public Variable graph template

  1. Ensure appParams exists, and initializes before running the public variable refresh, and ensure the appParams table includes the refresh rate.
  2. Create a new subgraph from the Refresh Public Variable graph template, and place near the start of your graph.
  3. Update the first Get node to reference your public variable. Updating the Get node tests if the public variable initialized.
    • If the public variable is not initialized, then the variable will go straight to the business logic to set its value – (the Refresh Public Variable graph assumes the default value of the variable is notSetSet).
    • If the public variable is populated, then the variable will run the decidePublicVariableRefresh script to determine whether enough time has passed since the public variable last refreshed.
  4. Set the arguments on the decidePublicVariableRefresh script – pvName, location of the public variable, appParams.
    • The decidePublicVariableRefresh script tests the public variable last refresh timestamp (stored in pvInfo public variable) elapsed X minutes ago.
  5. Create the business logic to set the value of the public variable.
  6. Set the arguments of the setPublicVariableLastRefreshTs which stores the last refresh timestamp into the pvInfo public variable.