I have an asynchronous script that fetches data from various websites in a loop; it takes a long time, nearly an hour, to get through, and only needs to be run very occasionally.
For local development purposes, I’d like to know how to stop the script. Currently, when I type ctrl + c, it quits meteor, but as soon as I restart meteor, the script restarts. Although this is handy for production in case something fails, I need to be able to stop the process, as I really don’t need it to complete in my local environment.
Is there a way to do this? meteor reset works, but I don’t want to reset my database…
How are you calling / starting your server script? It shouldn’t automatically restart unless you’re specifically telling Meteor to run the script on startup.
Thanks guys. The basic functionality is like this (simplified):
//asynchronous loop function
var i = 0;
(function createLinks(){
//data.data is imported from a csv, basically a list of URLs
var url = data.data[i].url;
//using Astronomy, basically this is equal to Links.insert({etc...})
link = new Link();
link.set({
url: url,
notes: notes,
type: category.split(',')
});
i = i + 1;
//save the link obj to the server and scrapes content from the URL
Meteor.call('saveLink', link, function(){
if(i < data.data.length){
createLinks();
} else {
console.log('All finished!');
}
});
})();
I’m not sure where in there Meteor tells it to continue the script on startup.
Sorry, I should have mentioned that it’s in a template event (an onclick handler). That changes things, right? The curious thing is that it resumes right where it left off, with the same data.
Yes it does - when the DDP client reconnects it resumes any method calls that were queued until the connection is re-established. If you want better control over the long running job, I’d suggest looking into the job-collection package. It will give you complete (and easy) control over any running job.
That explains what’s happening, so it’s the method calls. I was just checking out job-collection earlier today, I like what they’ve done and will see how I can apply this. In the meantime, is there a way to stop the method calls from resuming?