0

Just discovered Node.io, gone though the docs, api, etc. and it looks great. However, building my first job exports.job = new nodeio.Job(..), with methods like input, run,output, reduce, complete I'm in need of some kind of initialize() method which is called once, before successive calls to input() are done. (Similar how complete is called once just before the job is finished)

Any such method around?

For completeness: This code imho has to be part of the node.io flow (through some dedicated method) since initializing my async code outside of the node.io scope doesn't guarentee the data is already there before the node.io job is executed.

Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
  • Perhaps I should have been more explicit. I'm defining a node.io Job, with methods like `input, run,output, reduce, complete`. Of course in that file (before doing `exports.job = new nodeio.Job(..) )` I could initilize some data, but I need some async intializing code (a mongodb query-result) . In the abobe case this results in my async init code not being done (obviously) before the job is run. ALternatively I tried to call `exports.job = new nodeio.Job` in the callback of my async init-code but that resulted in a node.io error. Therefore looking for a dedicated node.io method for this. – Geert-Jan Nov 16 '12 at 16:22
  • Please put this all in your question. Formatted. Thank you. – Naftali Nov 16 '12 at 16:23
  • I will for completeness. However I must ask, are you familiar with the Node.io library? Because, my comment seems rather superfluous for those familiar with the api. – Geert-Jan Nov 16 '12 at 16:27

1 Answers1

0

I don't know if there is such a method, have you browsed through the source? It looks like there is an 'init' method that is called by the processor if it is on the job. If you try that and it isn't what you're looking for, you could suggest this as a feature on the node.io github site.

Otherwise, this would be a very simple thing to add for yourself. Just add an 'initialize' method to your object, and then put the following lines at the top of your 'input' or 'run' method (which I think would probably work better if you need the data to be ready already):

if (!this.initialized) {
   this.initialized = true;
   this.initialize();
}

Note that there is a tiny performance hit here, of course. But in most cases, it's only the amount of time it takes to check the value of one variable, which is probably quite minimal compared to the amount of processing you actually need.

user4815162342
  • 2,058
  • 3
  • 18
  • 23
  • Thanks. I ended up doing the init code inline in the `input` method. It's async code, but other than that it's like you suggested. – Geert-Jan Dec 13 '12 at 23:51