rake-task

Rake task failing to load :environment properly

[亡魂溺海] 提交于 2019-12-10 10:31:31
问题 I'm running a custom rake task... namespace :import do desc "Import terms of service as HTML from stdin" task :terms => :environment do html = STDIN.read settings = ApplicationWideSetting.first settings.terms_and_conditions = html if settings.save puts "Updated terms of service" else puts "There was an error updating terms of service" end end end The model ApplicationWideSetting is reported as undefined when running the task in the production environment. However, when running the task on

Rspec Rake Task: How to parse a parameter?

醉酒当歌 提交于 2019-12-10 10:16:10
问题 I have a rake task which generates a new User. Values of email, password and password_confirmation (confirm) needs to be typed in through the command line. This is my rake task code: namespace :db do namespace :setup do desc "Create Admin User" task :admin => :environment do ui = HighLine.new email = ui.ask("Email: ") password = ui.ask("Enter password: ") { |q| q.echo = false } confirm = ui.ask("Confirm password: ") { |q| q.echo = false } user = User.new(email: email, password: password,

How do you declare a Rake task that depends on a parameterized task?

落花浮王杯 提交于 2019-12-09 07:36:13
问题 I have seen examples where a task has parameters and a dependency task like: task :name, [:first_name, :last_name] => [:pre_name] do |t, args| args.with_defaults(:first_name => "John", :last_name => "Dough") puts "First name is #{args.first_name}" puts "Last name is #{args.last_name}" end How would you pass parameters to the name task if it was a task dependency like: task :sendLetter => :name #do something end 回答1: Args are passed down through the call stack. You just need to make sure your

Rails Execute Cron Job or Rake task for specific time period

吃可爱长大的小学妹 提交于 2019-12-08 11:40:32
问题 I want to execute some task for a specific time period. Lets say I want to execute cronjob or some rake task between 6am to 9am for every half an hour. So script will get execute 6, 6:30, 7, 7:30... and last at 9. Can you please give me some suggestion that how I can do this with Rails. Don't tell me that schedule individual task for 6, 6:30, 7.. time period. ANS Simplest way I have found is to use whenever gem and adding cronjob time as below. every '*/30 6-9 * * *' do runner "Model.method"

How to pass different arguments in rake multitask

可紊 提交于 2019-12-07 18:46:01
问题 I want to pass different arguments to every method and need to run all methods parallel using rake task Here is rake task calling example Rake::Task['test:sync'].invoke(user.id, user.address) Rake::Task['test:sync'].invoke(user.id, user.address) Rake::Task['test:sync'].invoke(user.id, user.address) I have seen the multitask example like this multitask :copy_files => [:copy_src, :copy_doc, :copy_bin] do puts "All Copies Complete" end Here they are calling with the task name alone. But in my

How can I run a ruby class from rake file?

ぃ、小莉子 提交于 2019-12-07 11:14:07
问题 I want to run a ruby class from a sample.rake file. Consider myruby.rb is a ruby file. I want to run this from sample.rake like ruby myruby.rb 回答1: Adding to what @tobias has to say here you go with an example script sample content of myruby.rb puts "hello world" Create file called Rakefile task :default => [:test] task :test do ruby "my_file.rb" end Now if you invoke rake it should file up hello world text in console. Update It would make more sense if you wrap your call in a function call

how to run rake task in background in rails

你。 提交于 2019-12-07 10:18:45
问题 This is my command bundle exec rake resque:work QUEUE="*" --trace I want to run this command on my server as a background process. please help me. 回答1: A method I often use is: nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 & This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do: tail -f rake.out And you can examine rake.out at any time. If you need to kill it before completion, you can find it with ps and

Ruby rake loaderror - bundle exec rake not working

北城以北 提交于 2019-12-07 09:01:18
问题 I'm trying to run the command rake db:migrate but I keep getting this error: /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `load': cannot load such file -- /Users/[name]/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/specifications/default/bin/rake (LoadError) from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>' from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval' from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>' Trying

Rails 3.1: how to run an initializer only for the web app (rails server/unicorn/etc)

a 夏天 提交于 2019-12-07 00:57:17
问题 My webapp needs to encrypt its session data. What I setup is: config/initializers/encryptor.rb: require 'openssl' require 'myapp/encryptor' MyApp::Encryptor.config[ :random_key ] = OpenSSL::Random.random_bytes( 128 ) Session.delete_all app/models/session.rb: require 'attr_encrypted' class Session < ActiveRecord::Base attr_accessible :session_id, :data attr_encryptor :data, :key => proc { MyApp::Encryptor.config[ :random_key ] }, :marshal => true # Rest of model stuff end That all works great,

run rake task inside rails application

梦想的初衷 提交于 2019-12-06 13:53:42
I want to run asset precompile task inside the rails application,As I had many dependencies who will change the code,in that case all the time whenever they change i need to run the script as I cant give server access to them so I am providing the GUI for them from that they alone can run the script,so,I have built UI to run the task with some parameter like system("Template='#{params[:template]}' Theme='#{params[:theme]}' rake assets:precompile) I am getting two values from UI(params[:template],params[:theme]).Another thing i want to run this task in another path(site path) means Admin side