FAQ Database Discussion Community


Rake task variable under namespace

ruby-on-rails,ruby,rake,rake-task
I see a strange thing in my rake script today. I have two Rake tasks under the different namespaces like following: path = "/home/tomcat/tomcat" namespace :stage do path = "/home/tomcat/stage-tomcat" desc "Deploys a java application to stage tomcat" task :java_deploy do puts path # stage:java_deploy should print /home/tomcat/stage-tomcat end end...

How to convert a rake task into a simple function call in a ROR application?

ruby-on-rails,ruby,rake-task
I am new in ROR, so my question is probably easy. However, I would like to explain my state. I have a ruby project1 which serves as a library. From this project I am interested in 1 rake task with this specific form: rake function1: function2 [arg1, arg2] Then, I...

Rake namespace not recognizing a local task

ruby,rake,rake-task
I am learning Ruby and trying to experiment with parsing arguments and having trouble with this example I made. The Rake namespace is not recognizing a local task. The :example task works fine. The :exampleAlt task is not working. The error is: $ rake myapp:exampleAlt rake aborted! NameError: undefined local...

Not setting arguments properly in rails tasks?

ruby-on-rails,ruby,rake,rake-task,rakefile
I am curious as to why my args variable is always coming back as {} in the following task: desc "Create an Api Key assuming one doesn't exist." task :create_api_key, [:name] => :environment do | t, args | if !ApiKey.find_by_application_name(args[:name]) binding.pry if ApiKey.new(:application_name => args[:name], :api_key => SecureRandom.hex(32)).save! puts "Your...

Update huge data in rake task

ruby-on-rails,ruby,postgresql,rake-task
i have a model named PageDensity which has about 5m rows. When i created project PageDensity table stored float of 5 decimal precision in density coulmn. Now the requirement changed to round it to two decimal places. I simply wrote a task to round all the densities but it makes...

Rake Task not working on Heroku

ruby-on-rails-4,heroku,rake-task
I am trying run a Rake Task that insert records in DB, but when i run this rake task, i see this error: NameError: uninitialized constant Classified Classified is a model on the DB. This Rake task work well on my local machine (development and production RAILS_ENV). heroku not allow...

Why does http request fail when running from rake task in a thread?

ruby,multithreading,rake,rake-task
I am trying to figure out why the following code does not work. The response is not printed out and from other research the request fails. task :test_me do t1 = Thread.new do puts 'start' uri = URI.parse("http://google.com/") response = Net::HTTP.get_response(uri) puts response.inspect # this line not getting printed end...

RSpec test for rake task

ruby-on-rails,ruby,rspec,rake-task
I have created a custom rake task that deletes all items that are >= 7 days old. I am trying to write a RSpec test for this new task but it seems like my task isn't really running in the test. I have tested the task manually and it works...

Loading Rails Environment when running rake tasks using Rufus scheduler and Sidekiq

ruby-on-rails,rake-task,rufus-scheduler
What I am trying to accomplish is to run some custom rake tasks on set intervals using rufus-scheduler. Here is my task_scheduler.rb require 'rufus-scheduler' require 'rake' load File.join(Rails.root, 'lib', 'tasks', 'worker_runner.rake') s = Rufus::Scheduler.new s.every '1m' do Rake::Task['auto_visit'].reenable Rake::Task['auto_visit'].invoke end s.every '5m' do Rake::Task['room_master'].reenable Rake::Task['room_master'].invoke Rake::Task['room_key'].reenable Rake::Task['room_key'].invoke end s.every '15m'...

How do you use multiple tasks using Rake::TestTask?

ruby,testing,rake,minitest,rake-task
I am running Minitest with Rake and would like to have two separate Rake tasks. I have added the following: require 'rake/testtask' task :default => [:test] task :quick => [:unit] Rake::TestTask.new do |t| puts 'within test task' t.libs.push 'specs' t.pattern = 'specs/*_spec.rb' ENV['STACK'] = 'stack1' puts "test stack #{ENV['STACK']}" end...

Run Raketask after capistrano deployment

ruby-on-rails,deployment,rake-task
How is it possible to run a rake task after the deployment has been finished? I tried the following: namespace :add_records do desc "Run a task on a remote server." task :default do run("cd #{deploy_to}/current; /usr/bin/env bundle exec rake my_task_group:test_records RAILS_ENV=#{rails_env}") end The task gets executed during the deployment but...

Rails - can not access table from within rake task

ruby-on-rails,ruby,rake,rake-task
I am trying to create a rake task which querries an API and adds records to a table. However, I can not access that table (I get the following error). ActiveRecord::StatementInvalid: Could not find table 'exchange_rates' My code is: namespace :query_api do task get_currency_values: :environment do exchange_rate = ExchangeRate.new #some...

Why doesn't it know how to build this task?

ruby-on-rails,rake,rake-task,rakefile
So I have the following task in rails running on jruby: desc "Creates a new site with args: name, api_url (must be http(s)://api.something.com/v1/ - note the ending slash), api_key" task :add_new_site, [:name, :api_url, :api_key] => :enviroment do | t, args | if !Site.find_by_site_name(args[:name]) new_site = Site.new(site_name: args[:name], site_api_url: args[:api_url], site_api_key:...

Passing arguments to a method in Rake Task [duplicate]

ruby-on-rails,ruby,command-line-arguments,rake-task
This question already has an answer here: How do I pass command line arguments to a rake task? 15 answers I have a Rake task wherein I am taking two arguments from command line and i need to pass those arguments to the method inside the task. How do...

How do I use File#join with File::ALT_SEPARATOR?

ruby,rake-task,albacore
I want to use File.join() for building paths in Ruby: File.Join("Dir1", "Dir2", "Dir3") Result is: Dir1/Dir2/Dir3 I want File.join() to uses File::ALT_SEPARATOR for doing this: Dir1\Dir2\Dir3 How do I do this?...