Hey, is there a way to persist a variable in the m...
# dev-ops
a
Hey, is there a way to persist a variable in the map/reduce stages? I'm creating a record, in the getInputData and I need to persist the ID across all stages. What's the pattern for this type of need, without inpacting the data passed from all stages as business data?
e
Probably better posed in #C29HQS63G , but you can either write the data to all stages, or you can use the
N/cache
module to store and retrieve it.
k
I've used a global variable before, the problem in it will loose the value in some point, I suggest you getting this from a file. Use it if it is still loaded, if not get the value again from the file
e
When you create the data object in the getinputdata stage include a property in the recordset for the value of your global variable.
e
Global variables will not persist across stages
And if you use a file, you likely still need to retain the ID of the file across the stages. Unless you use the same file all the time, but then that won't work for concurrent executions of the script
k
No, it should be an already pre-set file
e
Pre-set where, and by what?
k
In the code or script parameter
I mean the name / id
e
That works, so long as you know that you will never have two instances of the MR running concurrently
👆 1
e
@erictgrubaugh is right. The cache module is your friend in this scenario.
s
Another friend in this scenario is a Scheduled Script which has a single memory space for the entire duration of script execution.
e
*Until it reschedules
^ That's likely what "for the duration" is intended to imply, but I thought it was worth pointing out explicitly that you run into a similar persistence issue once the Scheduled Script is re-scheduled.
s
true that!
w
@erictgrubaugh using the cache-module. How would you allow for multiple concurrant instances of the same MR? I guess you could getCache() for the scriptId and then put() in getInput using the deploymentId as the key. That would allow you to retrieve which deployment is running and get the current value for that deployment. Since the same deployment can't run concurrently, it should be safe. Only worry would be if the script is executing for a very long time and the cache i removed by Netsuite ahead of the ttl. Storing the data in a field in a record/file would maybe be more safe. The properties could be stored in the file as JSON per deploymentId.
e
Only worry would be if the script is executing for a very long time and the cache i removed by Netsuite ahead of the ttl.
This is always the worry when using the cache module
e
Here's a cache question.... does the TTL timer restart every time the cached value is requested?