rake-task

newbie: error message when 'rake -T'

為{幸葍}努か 提交于 2020-01-01 09:10:11
问题 I am using Ruby Enterprise Edition for my project. When I check all my rake task by run the command rake -T , I got the following error message: You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this. The error message implies that I can use bundle exec to solve the problem, but I am not sure how? So, how to get rid of this error message? ------------------------------ more --------------------------- I prefer to update my Gemfile

whenever + delayed_job with cron job in starting worker

烂漫一生 提交于 2019-12-25 08:16:22
问题 I am learning cron job and delayed job, and I want to send emails using background job; for that I'm using the delayed_job gem. I don't want to start the worker manually by running the rake jobs:work command, but I want to set this rake in cron job so whenever an user login into the dashboard this command is fired and a mail is sent to his address. Following is my code: Sending mail method def dashboard @user = User.find(params[:id]) UserMailer.delay.initial_email(@user) end UserMailer def

rake task with multiple parameters - I got stuck

我怕爱的太早我们不能终老 提交于 2019-12-24 19:25:41
问题 The rake task itself: desc "This task creates a new user" task :create_user, [:email, :password] => :environment do |t, args| trole = Role.find_by_name('translator') User.create( :email => args.email, :password => args.password, :password_confirmation => args.password, :role_id => trole.id) end The call: rake create_user[user@host.com,password] The output: rake aborted! Don't know how to build task 'create_user' I really got stuck. All the advices I've found, even here, on StackOverflow,

Best way to trigger an hour before event starts

痴心易碎 提交于 2019-12-24 16:19:01
问题 I have many Appointment models that start at various times of the day, either at :00, :15, :30, :45 . I'd like to trigger code to send a reminder 1 hour before the event starts. What would be the best way to use a background worker to trigger this? I'm using the clockwork gem as well so I can schedule Sidekiq workers. 回答1: The clockwork gem is for fixed schedule jobs (a replacement for cron). You'll want to use ActionMailer.delay_until that comes with sidekiq : class Appointment after_create

Rails 3: How to intercept any http request

坚强是说给别人听的谎言 提交于 2019-12-24 00:23:55
问题 Lets say I have an image at app/assets/images/privateimages/myrestrictedimage1.jpg If I try to go directly to the image via url say with something like http://localhost:5555/assets/privateimages/myrestrictedimage1.jpg I am able to view the image. I would like to have a way to inspect any http request to decide if the user is allowed access to it. I know I can use before_filter in controllers to do some preprocessing before continuing onto any of the controller actions but I dont think this

accessing rails models from rake task

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:54:45
问题 How can I access model objects from rails rake task? If I initialize my rufus scheduler $scheduler = Rufus::Scheduler.start_new in my rake would that scheduler stay alive since it's from a rake task? 回答1: To access a rails model in your rake task you need to load the :environment. task :my_task => [:environment] do User.new #... end You would not call the scheduler within a task but the other way around. You need to start a Rufus scheduler and then call your rake tasks from them. You need to

Custom rake task for DB: Table not found

牧云@^-^@ 提交于 2019-12-23 15:43:38
问题 I have a custom rake task, that creates a development DB with data for various situation. The core looks like this: namespace :db do task setup_seed: :environment do Rake::Task['db:drop'].invoke Rake::Task['db:create'].invoke Rake::Task['db:schema:load'].invoke Rake::Task['db:migrate'].invoke Rake::Task['db:test:prepare'].invoke Rake::Task['db:seed'].invoke end end Everything runs fine, until db:seed is invoked, because it throws an error that tables does not exist. This is my seed.rb : puts

Set Multiple Environmental Variables On Invocation of Rake Task

空扰寡人 提交于 2019-12-23 09:03:02
问题 I can invoke a Rake task and set a single environmental variable like this: $ ONE=1 rake temp:both But how do I set two environmental variables? This doesn't work: $ ONE=1 TWO=2 rake temp:both This works, but is confusing to read: $ ONE=1 rake temp:both TWO=2 How can I pass more than one env before the call to rake ? 回答1: Agree with @Ernest; it should work. Here's a sample... Sample rake task to echo vars: task :echo_env do puts "VAR1: #{ENV['VAR1']}" puts "VAR2: #{ENV['VAR2']}" end Execute

Failed to launch child process

时间秒杀一切 提交于 2019-12-23 06:13:11
问题 When I try to run a test on Chrome (selenium / Ruby) then I get the following error. Could anybody help to resolve this? Error :- Background: Login to app # tests\integration\channels.feature:3 [6100:7920:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134949

Failed to launch child process

蓝咒 提交于 2019-12-23 06:12:26
问题 When I try to run a test on Chrome (selenium / Ruby) then I get the following error. Could anybody help to resolve this? Error :- Background: Login to app # tests\integration\channels.feature:3 [6100:7920:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134946:ERROR:child_process_launcher.cc(533)] Failed to launch child process [6100:9520:1028/134949