Tag: rake

如何使用Rails发条gem来运行rake任务?

从发条中调用rake任务的语法是什么? 我尝试过各种语法,似乎没什么用。 (我对钟表工作特别感兴趣,因为Heroku支持它。) 这是我的clock.rb,使用的是when gem使用的相同语法: module Clockwork puts “testing clockwork!” every(30.seconds, ‘Send Messages’) { rake ‘scheduler:send_messages’ } end 这是我在scheduler.rake中的rake任务: task :send_messages => :environment do puts “rake task run successfully!” end 这就是我开始发条过程时会发生的事情: $ clockwork lib/clock.rb testing clockwork! I, [2012-07-16T14:42:58.107245 #46427] INFO — : Starting clock for 1 events: [ Send Messages ] I, [2012-07-16T14:42:58.107364 #46427] INFO […]

每分钟运行一次的邮件的最佳导轨解决方案

我有一个应用程序,每分钟检查一次数据库,以查找当时应该发送的任何电子邮件。 我正在考虑将这个作为一个rake任务,每分钟由一个cron作业运行。 会有更好的解决方案吗? 从我所读到的,这不是理想的,因为rake必须每分钟加载整个rails环境,这变得昂贵。 思考? 谢谢。

生产佣金任务不承认我的模型

当我运行Heroku Bamboo时,这从来都不是问题。 现在,在Cedar上,每当我尝试从服务器上的rake任务中访问我的模型时,我都会收到错误。 rake db:seed ,标准rake任务以及我自己的自定义构建任务明确包括:environment。 我甚至多余地这样做: namespace :db do desc “Update db” task :new_seed => :environment do require ‘./Scraped_Data/Games/code/column-headers.rb’ require ‘csv’ require ‘net/http’ require ‘./config/environment.rb’ # code here… end end 我在其他地方找不到任何关于这个问题的提及,所有这些任务都在开发中完美运行。 感谢您的任何见解,这里是完整的错误消息,一旦他们在Heroku上遇到我的模型,rake任务就会吐出来: rake aborted! uninitialized constant Object::Movie /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing’ /app/lib/tasks/new_seed.rake:187:in `block in load_scraped_data’ /app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open’ /app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open’ /app/lib/tasks/new_seed.rake:148:in `load_scraped_data’ /app/lib/tasks/new_seed.rake:550:in `block (2 levels) in […]

没有这样的文件加载 – rdoc / task

当我跑 rake db:create 我收到此错误 rake aborted! no such file to load — rdoc/task (See full trace by running task with –trace) 这是–trace /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require’ /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require’ /home/tpeg/rails_apps/Test/Rakefile:8 /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:78:in `load_rakefile’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:61:in `run’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run’ /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/bin/rake:32 /usr/bin/rake:19:in `load’ /usr/bin/rake:19 我安装了rake 0.9.2和rdoc 3.11。 我在我的应用程序目录中运行这些命令。

如何通过rake任务导入CSV文件?

我知道这个问题已经在这个论坛上被问了很多,但是我在一个严格的截止日期之前,我需要一些帮助,所以任何建议都非常感谢。 我是Ruby on Rails的新手,所以请在回复时记住这一点。 我想创建一个rake任务,在运行时,更新mysqlite db中的多个表。 这是一个在我的数据库中创建新事件的迁移文件。 如何创建rake任务,通过CSV文件输入所有这些信息。 有人可以从头到尾写一些rake文件给我一些帮助。 显然你不需要为每个字符串编写每个任务,只需举几个例子。 除了实际的rake文件之外,我是否需要将代码添加到我的应用程序的任何其他部分(我知道这是一个非常普遍的问题,但如果我确实需要添加代码,我将非常感谢对其中的一般描述)。 我觉得会有一些指导意见。 如果有人需要我的任何更多信息,请询问。 class CreateIncidents < ActiveRecord::Migration def self.up create_table :incidents do |t| t.datetime :incident_datetime t.string :location t.string :report_nr t.string :responsible_party t.string :area_resident t.string :street t.string :city t.string :state t.string :home_phone t.string :cell_phone t.string :insurance_carrier_name t.string :insurance_carrier_street t.string :insurance_carrier_city t.string :insurance_carrier_state t.string :insurance_carrier_phone t.string :insurance_carrier_contact […]

Daemoninsing一个rake任务

我有一个rake任务,它在rails环境下运行mailman。 我想确保rake任务总是通过守护进程运行。 我的rake任务是rake incoming_mail 我该如何进行守护?

如何在environment.rb中检测我的rails是否在迁移中运行

任何简单的方法来检测它? 我想在进行迁移rake时跳过envirmonment.rb中的一些代码。

耙子流产! Heroku上未初始化的常量Rake :: DSL

当试图在Heroku上rake db:migrate时。 我收到以下错误。 rake aborted! uninitialized constant Rake::DSL 从我收集的内容来看,这似乎是Rake 0.9.2的一个错误。 如果我在本地执行“gem list”,则只安装Rake(0.8.7)。 我已经尝试将“gem’rake’,’0.8.7’”添加到我的gem文件并运行bundle install但是后来我收到以下错误。 You have requested: rake = 0.8.7 The bundle currently has rake locked at 0.9.2. Try running `bundle update rake` 如果我运行bundle update rake ,它会恢复到0.9.2,我回到了我开始的地方。 我错过了一些明显的东西吗?

bundle exec rake test:模型抛出Errno :: EACCES:权限被拒绝

我正在做railsstutorial的草稿版本,当我尝试运行bundle exec rake test:models我收到此错误消息: rake aborted! Errno::EACCES: Permission denied – C:/Users/Alex/Desktop/Workspace/Rails/sample_ app/db/test.sqlite3 C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/test_helper.rb:3:in `’ C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/helpers/application_helper _test.rb:1:in `’ Tasks: TOP => test:run => test:units (See full trace by running task with –trace) 使用–trace: ** Invoke test (first_time) ** Execute test ** Invoke test:run (first_time) ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Execute test:prepare ** […]

rake任务中的Railsexception通知程序

我有一个简单的rails应用程序,带有一些控制器和一些rake任务。 由gem配置的cron执行几个任务。 我的任务之一是每天执行,有时会引发exception,默认情况下我会收到cron的警告 rake aborted! undefined method `parameterize’ for nil:NilClass Tasks: TOP => mailboxes:clean_processed (See full trace by running task with –trace) 我想调试正在发生的事情,因此我刚刚在我的Gemfile使用此行安装了此exception通知 gem gem “exception_notification”, “~> 2.4.1”, :require => ‘exception_notifier’ 并在我的application.rb文件中配置它 # enable exception notification config.middleware.use ExceptionNotifier, :email_prefix => “[MyAppName] “, :sender_address => %{“notifier” }, :exception_recipients => %w{me@example.com} 由于这个gem是一个机架中间件,它只适用于Web请求而不适用于rake任务。 我也想为rake任务启用它,我找到了这个工作的要点 。 它工作,但它不是DRY,我需要在该方法中重复gem配置,我还需要更改所有我的rake任务,将它们的语句括在一个块中,如同 exception_notify { […]