0
votes

I am continually beating my head up against this desired feature, but I can't seem to find it in any of the NS2.x documentation.

I would like to persist script-runtime data across the multiple stages in the map/reduce architecture. For example: start time of getInputData stage, number of records processed, configuration data, etc.

However, all features seem to be designed to prevent this. Much of it (such as the configuration data) I've put into cache storage (via N/cache interface), but this comes with problems such as cache persisting across instances of the script running that will use an outdated or other-deployment configuration. I've had to create a per-session key of date/timestamp+user to keep things unique where necessary.

There is a Session object off of the N/runtime module, but this blanks itself out between stages, so it does not run on a true execution instance scope-- which is what I would expect a "session" to be. I have verified this with Debug trace that show the Session object to be non-blank at end of getInputData() stage, but completely empty when reaching the summary() stage. Even writing to the summaryContext does not seem useful or helpful, as only brief summary data can be written there.

Any help (or pointing to an already-answered question) would be useful; I can't seem to find this discussed anywhere on NetSuite help forums or on StackOverflow at all.

1
I should point out that cache data can only hold repeatable data creation as part of its content. This means that most of it will be based on record searches or data derived from those, not on stage-scope based information such as timestamps or record counts. That is why cache can't be used for all information, as it might be dropped and need to be recreated on demand by the script. - Donald Varona
I faced almost the same problem, and my advise is : you need to stop thinking about the notion "persisting" because like you said it is probably impossible. This doesn't mean you can't find a solution for your problem, you just must start thinking how to use the available options to solve it : It is what I always do, and it works. If you want, just update the question to explain what you want to do, and we can help suggesting the right architecture. - B. Assem
It turns out that most of the data that I am looking for is already in the summaryContext object. By "chance" as it were. - Donald Varona
But it is only impossible because of some blindness to this use case on Oracle's part. Because of this missing feature, I have had to compensate by: 1) Having the initiating Suitelet create a unique key for later grouping and pass that as a parameter; 2) Passing some undesirably complicated structures between the map() and reduce() stages; and 3) Dropping some field-related functionality usage between stages because record objects are collapsed to JavaScript objects - Donald Varona
Yeah I understand your frustration, I have been there too, but to be fair (playing the Devil's advocate :) ) : 1. It is not an oracle problem, Map/Reduce was there before Netsuite was acquired by Oracle. 2. I think this related to the fact that Map/Reduce stages are designed to be Run in parallel (in case you have mutiprocessor in your Netsuite account) : so passing some data between Maps/Reduces can be tricky + the fact that if one process fails, it doesn't affect the other ones and it will re-run automatically... so it is kind of an obligation to completely separate those "executions". - B. Assem

1 Answers

0
votes

Why not store what you want on a document using the N/file? I mean it's expensive, but should work without any conflicts.