a15n
a15n

Reputation: 507

"heroku run fileName" after grunt build

To learn more about heroku scheduling I read this post and built the app described in it. The key part of this post was when I was able to heroku run numCheck and the code within the numCheck file executed. After testing that heroku run numCheck worked I was able to schedule regularly occurring events in Heroku just fine.

I used yo angular-fullstack to create my app, Angel Insights and it's functional. However I want to add in heroku scheduling capabilities but I'm getting stuck. My problem is that I cannot run heroku run refresh in the Dist folder after I've run grunt build. Here's what I've tried specifically...

  1. Added bin/refresh before Grunt build (refresh code below)
  2. Added bin/refresh directly into the Dist folder after grunt build
  3. Tried heroku run anyFile after git push heroku master with both attempts

````````

#!/usr/bin/env node
var sendgrid  = require('sendgrid')(
  process.env.SENDGRID_USERNAME,
  process.env.SENDGRID_PASSWORD
);

var num1 = Math.ceil(Math.random() * 100);
var num2 = Math.ceil(Math.random() * 100);
var comparator;

if (num1 > num2) {
    comparator = "greater than";
} else if (num1 < num2) {
    comparator = "less than";
} else {
    comparator = "equal to";
}

sendgrid.send({
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Num1 v Num2',
    text: (num1 + ' is ' + comparator + " " + num2 + ".")
  }, function(err, json) {
    if (err) {
      console.error(err);
}

I'm really stuck and any insights are extremely appreciated!

Upvotes: 1

Views: 75

Answers (1)

David
David

Reputation: 537

With the angular generators you have to be careful about it overwriting the dist directory. Each time you grunt build you're going to start with a mostly clean dist dir.

The steps should be something like:

  1. grunt build
  2. cp refresh dist/refresh
  3. cd dist && git commit
  4. git push heroku master
  5. heroku run refresh

The main missing step being that you have to commit the copied file into dist after you copy it, otherwise heroku won't get it. You can always do heroku run ls or heroku run bash to see if your file is there.

After that works, you should look at your Gruntfile.js to make sure that refresh is copied there each time, you probably want to look at the copy task.

Upvotes: 3

Related Questions