Rake tasks

76 views
Skip to first unread message

Robert Fitzpatrick

unread,
Nov 18, 2014, 1:32:35 PM11/18/14
to rubyonra...@googlegroups.com
I am new to ruby and maintaining an existing web application. I need to
change the FTP server in a task and trying to familiarize myself with
rake tasks. The task is in lib/tasks/archives.rake under the namespace
utils. I read over a rake tutorial and viewed rake options to try and
show information about the task and possibly run it to test. But when I
do 'rake -T', I get a lot of DEPRECATED messages and the list afterward
does not have my task listed. This is how the task is defined:

namespace:utils do
<snip>
task :process_archives => :environment do
<snip>

But I have no task listed with that name? I tried 'rake -D
utils:process_archives' as well and only got the deprecated messages
output. I do see the task in the schedule.rb file...

./config/schedule.rb: command %{#{cmd_root} && cd
/var/www/vhosts/xxxx/current && bundle exec rake utils:process_archives
DIR="/var/www/vhosts/xxxx/shared/tmp" RAILS_ENV=production}

And the following file:

./script/process_archives.sh:rake utils:process_archives
DIR="/var/www/virtual/xxxx/htdocs/xxxx/tmp" RAILS_ENV="production"

The Rakefile looks like this:

require File.expand_path('../config/application', __FILE__)

XXXX::Application.load_tasks

Thanks for any help!

--
Robert

Michael Riley

unread,
Nov 18, 2014, 2:36:56 PM11/18/14
to rubyonra...@googlegroups.com
Hello,

What are the deprecated messages you are getting?

Mike Riley



--
Robert

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/546B909F.8060606%40webtent.org.
For more options, visit https://groups.google.com/d/optout.

Jason Fleetwood-Boldt

unread,
Nov 18, 2014, 2:46:30 PM11/18/14
to rubyonra...@googlegroups.com

Robert,

1) The same deprecation warnings probably happen when you just run "rails c" or "rails s", right? If so, those are just general deprecation warnings that are happening when you boot up the app. Today, you can ignore them (hence, warning). In the long run, you'll want to fix those as you upgrade gems and refactor code.

2) Custom rake tasks (defined in your app) should have a description above them. You actually put the description on its own line above the line that starts with the word "task" (slightly confusing). See the section "Describing Your Tasks" here http://jasonseifer.com/2010/04/06/rake-tutorial

You'll notice that desc comes on its own line before the task line. If you fail to put that description in, your Rake task will still run, but it won't show up in the rake -T output. 

Finally, you probably almost certainly don't want to be running RAILS_ENV="production" if you are developing locally on your own machine. And learn to use a debugger-- I recommend byebug if you're using Ruby 2.0 or above, and put "byebug" at the top of your rake task. Then just run your rask task and verify that you fall into the debugger. (I'm telling you this as a sanity check methodology because you are trying to verify that you know how to run the task)

Hope that helps.
-Jason
-- 
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+uns...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/546B909F.8060606%40webtent.org.
For more options, visit https://groups.google.com/d/optout.


----

Jason Fleetwood-Boldt
te...@datatravels.com
http://www.jasonfleetwoodboldt.com/writing

All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned into blog posts (original poster information will be made anonymous). Email ja...@datatravels.com with questions/concerns about this.

Robert Fitzpatrick

unread,
Nov 18, 2014, 3:33:57 PM11/18/14
to rubyonra...@googlegroups.com
Jason Fleetwood-Boldt wrote:
> Finally, you probably almost certainly don't want to be running
> RAILS_ENV="production" if you are developing locally on your own
> machine. And learn to use a debugger-- I recommend byebug if you're
> using Ruby 2.0 or above, and put "byebug" at the top of your rake task.
> Then just run your rask task and verify that you fall into the debugger.
> (I'm telling you this as a sanity check methodology because you are
> trying to verify that you know how to run the task)

Thanks for the info and help. The app is on ruby 1.9.3, I was running
rake on the production machine. I downloaded the app and have it running
locally, but there are some display issues with development, so I was
running production.

I see the task is running via cron every hour, it talks to an ftp server
and gets a file list, then creates playlist files from the list of MP3
files it finds. I see the task has a lot of puts when 'ARGV = V', should
I be able to run the task with the following command?

# rake utils:process_archive V'


--
Robert

Jason Fleetwood-Boldt

unread,
Nov 18, 2014, 3:43:59 PM11/18/14
to rubyonra...@googlegroups.com

Without seeing the task I can't tell you the answer to that. And the fact that it runs on a cron schedule means that you probably have something like a worker in the background doing that.

Normally you run

rake some_task X="abc" Y="xyz"

where X and Y are arguments being passed in.

But note that you probably want to prefix the rake task in development with "bundle exec" to get it to run with the right gemset.

-Jason

Robert Fitzpatrick

unread,
Nov 19, 2014, 12:49:50 PM11/19/14
to rubyonra...@googlegroups.com
Jason Fleetwood-Boldt wrote:
> Without seeing the task I can't tell you the answer to that. And the fact that it runs on a cron schedule means that you probably have something like a worker in the background doing that.
>
> Normally you run
>
> rake some_task X="abc" Y="xyz"

I see this piece of code at the start of the task assuming an argument
could be used to get the verbose response....

@verbose = false
ARGV.each do |arg|
puts "arg: #{arg}"
@verbose = false # if arg == 'V'
end

Then the code uses '#puts something if @verbose' throughout. Like I
said, I'm new to ruby, but have used Perl and PHP and other languages
before, I hope is what is throwing me off is the # are not comments?
This almost looks like @verbose would always be false. What is this
piece of code looking for as an argument?

I apologize for trying to get a crash course in ruby here, gonna have to
get up to speed soon as this app that was left to me to try and
maintain/support. I am reading through the following tutorial to get up
to speed as quickly as I can, any other pointers extremely helpful...

https://www.railstutorial.org/book


> But note that you probably want to prefix the rake task in development with "bundle exec" to get it to run with the right gemset.
>

I downloaded a copy of the app and setup locally on a development
server. The production app is running on nginx web server and have the
copy running on Apache locally. I saw the following directive available
in the nginx conf to enable development, copied to Apache and this is
how I am running dev mode...

RailsEnv development

Then I can run "bundle exec rake utils:process_archives"?

As I posted earlier, there is a script/process_archives.sh file that I
thought at first runs the rake task since I see results of the task in
the cron log...

rake utils:process_archives DIR="/var/www/virtual/xxxx/htdocs/xxxx/tmp"
RAILS_ENV="production"

But that DIR does not exist on the server, so I'm questioning if this
shell script is being used at all. I found further the task in
config/schedule.rb...

command %{#{cmd_root} && cd /var/www/vhosts/wmnf/current && bundle exec
rake utils:process_archives DIR="/var/www/vhosts/xxxx/shared/tmp"
RAILS_ENV=production}

Those dirs do exist and I also found in the crontabs...

root@app01:~/www# cat /var/spool/cron/crontabs/appuser |grep process
31 * * * * /bin/bash -l -c 'PATH=/opt/ree/bin:$PATH && cd
/var/www/vhosts/xxxx/current && bundle exec rake utils:process_archives
DIR="/var/www/vhosts/xxxx/shared/tmp" RAILS_ENV=production >>
/var/www/vhosts/xxxx/shared/log/cron.log 2>&1'

Is the scheduler.rb being used at all?

Another thing about running the app locally on a development server is
when I enable development as shown above, it breaks links to images,
css, etc. Seems there is something in the code to prefix the paths of
those resources with '/app_development/' when using development
environment. So, I'm running in production environment on the
development server. Other than references like this in the code for
development, what would be the difference between running a copy of the
app under the production or development environment on the development
server?

Again, thanks a ton for any help and patience, I promise to get up to
speed as quickly as possible.

--
Robert

Scott Ribe

unread,
Nov 19, 2014, 12:54:29 PM11/19/14
to rubyonra...@googlegroups.com
On Nov 19, 2014, at 10:49 AM, Robert Fitzpatrick <rob...@webtent.org> wrote:
>
> Then the code uses '#puts something if @verbose' throughout. Like I said, I'm new to ruby, but have used Perl and PHP and other languages before, I hope is what is throwing me off is the # are not comments? This almost looks like @verbose would always be false. What is this piece of code looking for as an argument?

You're reading things correctly.

# starts a comment
@verbose is always false in this code, and would be even if the if were not commented out

The code doesn't even make sense as the result of someone trying to comment out something to hard-wire @verbose to one value or the other...

--
Scott Ribe
scott...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Robert Fitzpatrick

unread,
Nov 19, 2014, 1:12:25 PM11/19/14
to rubyonra...@googlegroups.com
Scott Ribe wrote:
> On Nov 19, 2014, at 10:49 AM, Robert Fitzpatrick<rob...@webtent.org> wrote:
>> Then the code uses '#puts something if @verbose' throughout. Like I said, I'm new to ruby, but have used Perl and PHP and other languages before, I hope is what is throwing me off is the # are not comments? This almost looks like @verbose would always be false. What is this piece of code looking for as an argument?
>
> You're reading things correctly.
>
> # starts a comment
> @verbose is always false in this code, and would be even if the if were not commented out
>
> The code doesn't even make sense as the result of someone trying to comment out something to hard-wire @verbose to one value or the other...
>

OK, that's a relief that I can read the code, thanks for clarifying. To
get verbosity, I'll need to do a lot of uncommenting and do line-by-line
debuggging :-/

Jason mentioned a debugging tool for Rails 2.0 earlier, what about for
this 1.9.3, anything available to help?

--
Robert

Scott Ribe

unread,
Nov 19, 2014, 1:41:18 PM11/19/14
to rubyonra...@googlegroups.com
On Nov 19, 2014, at 11:12 AM, Robert Fitzpatrick <rob...@webtent.org> wrote:
>
> OK, that's a relief that I can read the code, thanks for clarifying. To get verbosity, I'll need to do a lot of uncommenting and do line-by-line debuggging :-/
>
> Jason mentioned a debugging tool for Rails 2.0 earlier, what about for this 1.9.3, anything available to help?

Maybe I missed something earlier in the discussion, but can't you just edit it to:

@verbose = true if arg == 'V'

Robert Fitzpatrick

unread,
Nov 19, 2014, 2:45:02 PM11/19/14
to rubyonra...@googlegroups.com
Scott Ribe wrote:
> On Nov 19, 2014, at 11:12 AM, Robert Fitzpatrick<rob...@webtent.org> wrote:
>> OK, that's a relief that I can read the code, thanks for clarifying. To get verbosity, I'll need to do a lot of uncommenting and do line-by-line debuggging :-/
>>
>> Jason mentioned a debugging tool for Rails 2.0 earlier, what about for this 1.9.3, anything available to help?
>
> Maybe I missed something earlier in the discussion, but can't you just edit it to:
>
> @verbose = true if arg == 'V'
>

Yes, I guess so, and then uncomment all the places in the code where he
has....

#puts <something> if @verbose

I'll give it a try, still trying to figure out how to run the task. I
put the app in development environment with the Apache directive and
this is all the deprecated info I mentioned and other output when trying
to "bundle exec", I get "Don't know how to build task 'utils:archives'".
Is this how I should be trying to run the task?

$ bundle exec rake utils:archives --trace
Your Gemfile lists the gem sitemap_generator (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the
version of just one of them later.
Your Gemfile lists the gem backup (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the
version of just one of them later.
Your Gemfile lists the gem awesome_print (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the
version of just one of them later.
Your Gemfile lists the gem awesome_print (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the
version of just one of them later.
DEPRECATION WARNING: Calling set_table_name is deprecated. Please use
`self.table_name = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Calling set_primary_key is deprecated. Please use
`self.primary_key = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Calling set_table_name is deprecated. Please use
`self.table_name = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Calling set_primary_key is deprecated. Please use
`self.primary_key = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Calling set_table_name is deprecated. Please use
`self.table_name = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Calling set_primary_key is deprecated. Please use
`self.primary_key = 'the_name'` instead. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: Support for Rails < 4.0.4 will be dropped from
Formtastic 4.0. (called from require at
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:76)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!
Support for these plugins will be removed in Rails 4.0. Move them out
and bundle them in your Gemfile, or fold them in to your app as
lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this:
http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called
from <top (required)> at /backup/storage/sites/wmnf/wmnf.org/Rakefile:7)
rake aborted!
Don't know how to build task 'utils:archives'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in
`[]'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:149:in
`invoke_task'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:106:in
`block (2 levels) in top_level'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:106:in
`each'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:106:in
`block in top_level'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:115:in
`run_with_threads'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:100:in
`top_level'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:78:in
`block in run'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:176:in
`standard_exception_handling'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/lib/rake/application.rb:75:in
`run'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.3.2/bin/rake:33:in
`<top (required)>'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in `load'
/home/robert/.rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in `<main>'
/home/robert/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in
`eval'
/home/robert/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in
`<main>'

--
Robert

Robert Fitzpatrick

unread,
Nov 19, 2014, 5:11:39 PM11/19/14
to rubyonra...@googlegroups.com
Robert Fitzpatrick wrote:
>> Maybe I missed something earlier in the discussion, but can't you just
>> edit it to:
>>
>> @verbose = true if arg == 'V'
>>
>
> Yes, I guess so, and then uncomment all the places in the code where he
> has....
>
> #puts <something> if @verbose
>
> I'll give it a try, still trying to figure out how to run the task. I
> put the app in development environment with the Apache directive and
> this is all the deprecated info I mentioned and other output when trying
> to "bundle exec", I get "Don't know how to build task 'utils:archives'".
> Is this how I should be trying to run the task?

Never mind my last post, I looked up the command used in cron and made
an adjustment to the DIR for my local box and got the expected response.

bundle exec rake utils:process_archives V DIR="/tmp"

I updated the verbose line to recognize the 'V' argument as suggested
and it does output the conditional puts lines, but I do get the
following at the end....

rake aborted!
Don't know how to build task 'V'

The task does appear to complete successfully, with comments if I
specify 'V' and without if not, as expected. Is this normal or should I
be applying the argument differently?

--
Robert

Jason Fleetwood-Boldt

unread,
Nov 24, 2014, 12:36:46 PM11/24/14
to rubyonra...@googlegroups.com
Robert,

I can't tell you all the ins and outs of your script but what you're seeing here is that rake is looking at the V thinking it is another rake task you want to run (that's why the first one succeeds and then gives you the error)

You probably want something like V="true" or V=1 or something like that.

-Jason
Reply all
Reply to author
Forward
0 new messages