我有一个Rakefile,用于自动化项目中的某些任务.
在某些任务中,我调用system,但是,即使进程返回错误,任务也会继续,没有任何问题.
我怎么能避免这种情况?我想在某些子进程返回错误时使rake退出.
提前致谢
我试图用TDD让我的头"脏",出于某种原因,当我bundle exec rake test在命令行上运行时,没有任何反应.
这是我的RakeFile:
require 'rake/testtask'
Rake::TestTask.new do |test|
test.libs << 'test'
end
desc "Run Tests"
task :default => :test
Run Code Online (Sandbox Code Playgroud)
这是我的测试文件:
require 'test/unit'
class TestMygem < Test::Unit::TestCase
def test_silly_example
assert_equal 2+2, 5
end
end
Run Code Online (Sandbox Code Playgroud) 这是我的命令
bundle exec rake resque:work QUEUE="*" --trace
Run Code Online (Sandbox Code Playgroud)
我想在我的服务器上运行此命令作为后台进程.
请帮我.
如何ActionDispatch::Integration::Session在rails rake任务中获取实例.
我想能够打电话:app.get '/'就像你可以在rails控制台中做的那样.
我正在使用Ruby on Rails 3在AWS中执行cron选项卡 - Elastic Beanstalk,但我不知道出了什么问题.
我在.ebextensions/default.config中有这段代码
container_commands:
01remove_old_cron_jobs:
command: "crontab -r || exit 0"
02send_test_email:
command: crontab */2 * * * * rake send_email:test
leader_only: true
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Failed on instance with return code: 1 Output: Error occurred during build: Command 02send_test_email failed .
Run Code Online (Sandbox Code Playgroud)
更新1
我试过下一个:
crontab.txt
*/2 * * * * rake send_email:test > /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
default.config
02_crontab:
command: "cat .ebextensions/crontab.txt | crontab"
leader_only: true
Run Code Online (Sandbox Code Playgroud)
结果:没有错误,但它不起作用.
更新2
crontab.sh
crontab -l > /tmp/cronjob
#CRONJOB RULES
echo "*/2 …Run Code Online (Sandbox Code Playgroud) cron ruby-on-rails amazon-web-services rake-task amazon-elastic-beanstalk
我们有一个Rails 4应用程序.whenever使用夏令时在午夜美国的轨道中安排任务的最佳方法是什么?
我们需要在一天的报告中晚上11点59分发送电子邮件.
我们正在使用 tzinfo gem
TZInfo::Timezone.get('America/Denver').local_to_utc(Time.parse('11:58pm')).strftime('%H:%M%p')
Run Code Online (Sandbox Code Playgroud)
当时没有发送电子邮件.
我不知道wtf是怎么回事,但我刚创建了一个新的Rails应用程序,无法让任何rake任务工作或显示在 $ rake -T
LIB /任务/ hello.rake
namespace :hello do
desc "hello"
task :you do
puts "hello"
end
end
Run Code Online (Sandbox Code Playgroud)
$ rake -T
它没有出现在那里
$ rake hello:you
耙子流产了!不知道如何构建任务'你好:你'(参见--tasks)
的Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets …Run Code Online (Sandbox Code Playgroud) 我正在运行自定义rake任务......
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
Run Code Online (Sandbox Code Playgroud)
在production环境中运行任务时,ApplicationWideSetting模型报告为未定义 .但是,运行在其它环境(即任务时development,staging,test.)任务运行正常.
在所有环境中,在rails控制台中运行该过程都可以.
有谁知道发生了什么,我可以检查的事情?
注意:我运行任务
puts Rails.env
Run Code Online (Sandbox Code Playgroud)
要检查shell环境var RAILS_ENV是否正确设置/读取.我也尝试过:环境依赖声明周围有和没有方括号.
其他信息: Rails v3.2.14
进一步的信息:我已经设置了一个全新的rails应用程序,该脚本在任何环境下都能正常运行.由于有问题的安装是一个真实的生产环境,我将不得不设置另一个部署并彻底检查它.更多信息,因为我找到它.
我有一个主要的rake任务setup_a_new_set_of_snippets.rake,我调用,然后调用其他任务.所以主要看起来像这样:
load './lib/tasks/fetch_and_create_snippets.rake'
load './lib/tasks/generate_diffs_for_snippets.rake'
load './lib/tasks/cleanup_snippets_with_empty_diffs.rake'
desc "Setup a new set of Snippets"
task :setup_a_new_set_of_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
repo = args[:repo]
path = args[:path]
entry_id = args[:entry_id]
framework_id = args[:framework_id]
method_name = args[:method_name]
Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)
Rake::Task["generate_diffs_for_snippets"].invoke
Rake::Task["cleanup_snippets_with_empty_diffs"].invoke(framework_id)
end
Run Code Online (Sandbox Code Playgroud)
出于某种原因,fetch_and_create_snippets像这样运行的耙子Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)似乎运行了两次.
这是任务 - fetch_and_create_snippets.rake:
desc 'Fetch and Create Snippets from Github'
task :fetch_and_create_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
repo = args[:repo]
path = …Run Code Online (Sandbox Code Playgroud) 我有执行Nokogiri的方法.即下载页面,提取内容,复制到另一个表格......等.
这个方法是内部帮助器,我需要通过rake任务定期运行.
什么是在任务DRY中调用方法的正确方法.
将代码移动到任务文件移动到模型,普通红宝石一些其他建议......?
请提供rake任务的示例,包括帮助程序
顺便说一句:由于增加了另一个基础设施问题,我不想介绍工作.我现在更喜欢rake任务.在未来,我想转向一些像Sidekiq或类似的后台工作框架