I've just deployed a Sinatra app to heroku and the app contains two rake tasks:
task :create_db , [:db_id , :db_name]
task :destroy_db , [:db_id, :token]
When I run
heroku run rake -T
in the console, Heroku prints the following response:
(in /app)
rake create_db[db_id,db_name] # Creation count database task
rake destroy_db[db_id,token] # Destroy database task
However when I run:
heroku run rake create_db['test', 'test database']
It responds with the following error:
(in /app)
rake aborted!
Don't know how to build task 'create_db[test,'
/usr/local/lib/ruby/1.9.1/rake.rb:1720:in `[]'
/usr/local/lib/ruby/1.9.1/rake.rb:2040:in `invoke_task'
/usr/local/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level'
/usr/local/lib/ruby/1.9.1/rake.rb:2019:in `each'
/usr/local/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level'
/usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
/usr/local/lib/ruby/1.9.1/rake.rb:1992:in `run'
/usr/local/bin/rake:31:in `<main>'
I'm not quite sure why this is failing, however my guess is that it has to do with the string arguments. As you can see above, it says "don't know how to build task 'create_db[test,' with test showing up without strings.
Have any idea how to get this task to run from the command line?
From the Rake docs:
The rake task name and its arguments need to be a single command line argument to rake. This generally means no spaces. If spaces are needed, then the entire rake + argument string should be quoted. Something like this:
rake "name[billy bob, smith]"
(Quoting rules vary between operating systems and shells, so make sure you consult the proper docs for your OS/shell).
Also note that you don’t need to quote the individual parameters.
In your case this should work:
rake "create_db[test, test database]"
This also works:
rake create_db[test,'test database']
Note that the second parameter is quoted, but there is no space between the comma and the quote, so the shell treats the whole thing as a single argument.
This doesn’t work using heroku run
, because in this case the command gets interpreted by a shell twice, once by your own, and again on the Heroku Dyno, so you need to make sure the command as run by Heroku has the correct quotes.
You need to either escape the quotes:
heroku run rake \"create_db[test, test database]\"
so that the command run on the Dyno is rake "create_db[test, test database]"
; or quote the quotes:
heroku run rake "create_db[test,'test database']"
so that the command that gets run is rake create_db[test,'test database']
.
The reason
$ heroku run rake create_db['test', 'test database']
is not working is due to the space between/within the parameters.The following will work.
$ heroku run rake "create_db['test','test database']"
Well for me this works
heroku run rake "namespace:task['var1','var2']"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With