Reputation: 2192
For example, in a Ruby project you can use rake
to create and run tasks for performing manual operations. What is the equivalent, if any, when using Meteor?
Let's say I have a function inside a server/tasks.js
file:
Meteor.startup(function() {
function importData() {
// My code goes here
}
});
How do I run it from the command line using Meteor or some other task manager?
meteor importData
Upvotes: 3
Views: 312
Reputation: 1555
I solved a similar case by creating a Meteor method on the serverside that is triggered every time a client loads a page that needs the data. The method only executes the importData function if it hasn't been executed in the last hour.
This is a good pattern for things dat need to sync with remote data. I use it for importing stuff from Tumblr. The downside of this approach is that the method is not run when nobody visits the page. This is easily solved by adding a timer using Meteor.setInterval on the serverside.
Alternatively, if you really want to execute Meteor code from the command prompt, you could take a look at the following package: https://github.com/practicalmeteor/meteor-mcli
Upvotes: 1