From 0c232779ece1ff6bf9bce9d55c54ea19867a2170 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 12 Aug 2014 09:29:21 +0000 Subject: Remove activejob integration tests --- activejob/.gitignore | 2 - activejob/.travis.yml | 39 ---- activejob/Gemfile | 25 --- activejob/Gemfile.lock | 206 --------------------- activejob/Rakefile | 76 +++++--- activejob/test/cases/logging_test.rb | 1 + activejob/test/dummy/Rakefile | 3 - activejob/test/dummy/app/assets/images/.keep | 0 .../app/controllers/application_controller.rb | 3 - .../test/dummy/app/controllers/concerns/.keep | 0 .../test/dummy/app/helpers/application_helper.rb | 2 - activejob/test/dummy/app/jobs/test_job.rb | 9 - activejob/test/dummy/app/mailers/.keep | 0 activejob/test/dummy/app/models/.keep | 0 activejob/test/dummy/app/models/concerns/.keep | 0 activejob/test/dummy/config.ru | 4 - activejob/test/dummy/config/application.rb | 9 - activejob/test/dummy/config/boot.rb | 5 - activejob/test/dummy/config/database.yml | 3 - activejob/test/dummy/config/environment.rb | 2 - activejob/test/dummy/config/environments/test.rb | 13 -- .../test/dummy/config/initializers/activejob.rb | 65 ------- .../dummy/config/initializers/session_store.rb | 1 - activejob/test/dummy/config/routes.rb | 2 - activejob/test/dummy/config/secrets.yml | 2 - .../migrate/20140804200445_create_delayed_jobs.rb | 22 --- activejob/test/dummy/db/schema.rb | 32 ---- activejob/test/dummy/db/test.sqlite3 | Bin 24576 -> 0 bytes activejob/test/dummy/lib/assets/.keep | 0 activejob/test/dummy/log/.keep | 0 activejob/test/dummy/tmp/.keep | 0 activejob/test/helper.rb | 7 +- activejob/test/integration/queuing_test.rb | 18 -- .../support/integration/adapters/backburner.rb | 15 -- .../support/integration/adapters/delayed_job.rb | 14 -- activejob/test/support/integration/adapters/qu.rb | 14 -- activejob/test/support/integration/adapters/que.rb | 19 -- .../support/integration/adapters/queue_classic.rb | 21 --- .../test/support/integration/adapters/resque.rb | 18 -- .../test/support/integration/adapters/sidekiq.rb | 19 -- .../test/support/integration/adapters/sneakers.rb | 18 -- .../support/integration/adapters/sucker_punch.rb | 5 - activejob/test/support/integration/helper.rb | 12 -- activejob/test/support/integration/jobs_manager.rb | 23 --- .../test/support/integration/test_case_helpers.rb | 30 --- 45 files changed, 48 insertions(+), 711 deletions(-) delete mode 100644 activejob/.gitignore delete mode 100644 activejob/.travis.yml delete mode 100644 activejob/Gemfile delete mode 100644 activejob/Gemfile.lock delete mode 100644 activejob/test/dummy/Rakefile delete mode 100644 activejob/test/dummy/app/assets/images/.keep delete mode 100644 activejob/test/dummy/app/controllers/application_controller.rb delete mode 100644 activejob/test/dummy/app/controllers/concerns/.keep delete mode 100644 activejob/test/dummy/app/helpers/application_helper.rb delete mode 100644 activejob/test/dummy/app/jobs/test_job.rb delete mode 100644 activejob/test/dummy/app/mailers/.keep delete mode 100644 activejob/test/dummy/app/models/.keep delete mode 100644 activejob/test/dummy/app/models/concerns/.keep delete mode 100644 activejob/test/dummy/config.ru delete mode 100644 activejob/test/dummy/config/application.rb delete mode 100644 activejob/test/dummy/config/boot.rb delete mode 100644 activejob/test/dummy/config/database.yml delete mode 100644 activejob/test/dummy/config/environment.rb delete mode 100644 activejob/test/dummy/config/environments/test.rb delete mode 100644 activejob/test/dummy/config/initializers/activejob.rb delete mode 100644 activejob/test/dummy/config/initializers/session_store.rb delete mode 100644 activejob/test/dummy/config/routes.rb delete mode 100644 activejob/test/dummy/config/secrets.yml delete mode 100644 activejob/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb delete mode 100644 activejob/test/dummy/db/schema.rb delete mode 100644 activejob/test/dummy/db/test.sqlite3 delete mode 100644 activejob/test/dummy/lib/assets/.keep delete mode 100644 activejob/test/dummy/log/.keep delete mode 100644 activejob/test/dummy/tmp/.keep delete mode 100644 activejob/test/integration/queuing_test.rb delete mode 100644 activejob/test/support/integration/adapters/backburner.rb delete mode 100644 activejob/test/support/integration/adapters/delayed_job.rb delete mode 100644 activejob/test/support/integration/adapters/qu.rb delete mode 100644 activejob/test/support/integration/adapters/que.rb delete mode 100644 activejob/test/support/integration/adapters/queue_classic.rb delete mode 100644 activejob/test/support/integration/adapters/resque.rb delete mode 100644 activejob/test/support/integration/adapters/sidekiq.rb delete mode 100644 activejob/test/support/integration/adapters/sneakers.rb delete mode 100644 activejob/test/support/integration/adapters/sucker_punch.rb delete mode 100644 activejob/test/support/integration/helper.rb delete mode 100644 activejob/test/support/integration/jobs_manager.rb delete mode 100644 activejob/test/support/integration/test_case_helpers.rb (limited to 'activejob') diff --git a/activejob/.gitignore b/activejob/.gitignore deleted file mode 100644 index ee45263e91..0000000000 --- a/activejob/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/test/dummy/log/* -/test/dummy/tmp/* diff --git a/activejob/.travis.yml b/activejob/.travis.yml deleted file mode 100644 index fba12f9d0d..0000000000 --- a/activejob/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -before_install: -- travis_retry gem install bundler -- sudo apt-get update -qq -- sudo apt-get install beanstalkd -- echo "START=yes" | sudo tee -a /etc/default/beanstalkd -- sudo /etc/init.d/beanstalkd start - -rvm: -- 1.9.3 -- 2.0.0 -- 2.1 -- ruby-head -- rbx-2 -- jruby -env: -- QC_DATABASE_URL="postgres://postgres@localhost/active_jobs_qc_int_test" QUE_DATABASE_URL="postgres://postgres@localhost/active_jobs_qc_int_test" -matrix: - allow_failures: - - rvm: rbx-2 - - rvm: jruby - - rvm: ruby-head - fast_finish: true -notifications: - email: false - irc: - on_success: change - on_failure: always - channels: - - irc.freenode.org#rails-contrib - campfire: - on_success: change - on_failure: always - rooms: - - secure: AgZwJA+9VdnWAw7QN9Z5s6RpQIzsEB0q7V+p3pCzXY45156WocL8iNQx+KnyOQ8jbRUt4L/XIOiZl5xHf4pHjXytHWHNhetAlVQP/hPeDcCSk/h0g5gqgf6QABdp38tBNaUq866bXHgCOZYPwwP9bypcmuv2SLyfIO+b/PBgqN0= -services: -- redis -- rabbitmq -addons: - postgresql: "9.3" diff --git a/activejob/Gemfile b/activejob/Gemfile deleted file mode 100644 index 12a1798fd5..0000000000 --- a/activejob/Gemfile +++ /dev/null @@ -1,25 +0,0 @@ -source 'https://rubygems.org' - -gemspec - -gem 'rake' -gem 'resque' -gem 'resque-scheduler' -gem 'sidekiq' -gem 'sucker_punch' -gem 'delayed_job' -gem 'queue_classic' -gem 'sneakers', '0.1.1.pre' -gem 'que' -gem 'backburner' -gem 'qu-rails', github: "bkeepers/qu", branch: "master" -gem 'qu-redis' - -#for integration testing -gem 'arel', github: 'rails/arel' -gem 'rack', github: 'rack/rack' -gem 'i18n', github: 'svenfuchs/i18n' -gem 'rails', github: 'rails/rails' -gem 'sqlite3' -gem 'delayed_job_active_record' -gem 'sequel' diff --git a/activejob/Gemfile.lock b/activejob/Gemfile.lock deleted file mode 100644 index 53ba5c055b..0000000000 --- a/activejob/Gemfile.lock +++ /dev/null @@ -1,206 +0,0 @@ -GIT - remote: git://github.com/bkeepers/qu.git - revision: 50f3788f2b55ddd4dc939767fb35aebefa260322 - branch: master - specs: - qu (0.2.0) - qu-rails (0.2.0) - qu (= 0.2.0) - railties (>= 3.2, < 5) - qu-redis (0.2.0) - qu (= 0.2.0) - redis-namespace - -GIT - remote: git://github.com/rack/rack.git - revision: e98a9f7ef0ddd9589145ea953948c73a8ce3caa9 - specs: - rack (1.6.0.alpha) - -GIT - remote: git://github.com/rails/arel.git - revision: 66cee768bc163537087037a583f60639eae49fc3 - specs: - arel (6.0.0.20140505020427) - -GIT - remote: git://github.com/rails/rails.git - revision: b2e88043b52a8f83820a0f4e8a65aa42fd40c544 - specs: - actionmailer (4.2.0.alpha) - actionpack (= 4.2.0.alpha) - actionview (= 4.2.0.alpha) - mail (~> 2.5, >= 2.5.4) - actionpack (4.2.0.alpha) - actionview (= 4.2.0.alpha) - activesupport (= 4.2.0.alpha) - rack (~> 1.6.0.alpha) - rack-test (~> 0.6.2) - actionview (4.2.0.alpha) - activesupport (= 4.2.0.alpha) - builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.2.0.alpha) - activesupport (= 4.2.0.alpha) - builder (~> 3.1) - activerecord (4.2.0.alpha) - activemodel (= 4.2.0.alpha) - activesupport (= 4.2.0.alpha) - arel (~> 6.0.0) - activesupport (4.2.0.alpha) - i18n (>= 0.7.0.dev, < 0.8) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - rails (4.2.0.alpha) - actionmailer (= 4.2.0.alpha) - actionpack (= 4.2.0.alpha) - actionview (= 4.2.0.alpha) - activemodel (= 4.2.0.alpha) - activerecord (= 4.2.0.alpha) - activesupport (= 4.2.0.alpha) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.0.alpha) - sprockets-rails (~> 2.1) - railties (4.2.0.alpha) - actionpack (= 4.2.0.alpha) - activesupport (= 4.2.0.alpha) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - -GIT - remote: git://github.com/svenfuchs/i18n.git - revision: cb679b8cdbab675703a3f88de4d48a48f7b50e06 - specs: - i18n (0.7.0.dev) - -PATH - remote: . - specs: - activejob (4.2.0.alpha) - activemodel-globalid - activesupport (>= 4.1.0) - -GEM - remote: https://rubygems.org/ - specs: - activemodel-globalid (0.1.1) - activemodel (>= 4.1.0) - activesupport (>= 4.1.0) - amq-protocol (1.9.2) - backburner (0.4.5) - beaneater (~> 0.3.1) - dante (~> 0.1.5) - beaneater (0.3.2) - builder (3.2.2) - bunny (1.1.9) - amq-protocol (>= 1.9.2) - celluloid (0.15.2) - timers (~> 1.1.0) - connection_pool (2.0.0) - dante (0.1.5) - delayed_job (4.0.2) - activesupport (>= 3.0, < 4.2) - delayed_job_active_record (4.0.1) - activerecord (>= 3.0, < 4.2) - delayed_job (>= 3.0, < 4.1) - erubis (2.7.0) - hike (1.2.3) - json (1.8.1) - mail (2.6.1) - mime-types (>= 1.16, < 3) - mime-types (2.3) - minitest (5.4.0) - mono_logger (1.1.0) - multi_json (1.10.1) - pg (0.17.1) - que (0.8.1) - queue_classic (2.2.3) - pg (~> 0.17.0) - rack-protection (1.5.3) - rack - rack-test (0.6.2) - rack (>= 1.0) - rake (10.3.2) - redis (3.1.0) - redis-namespace (1.5.1) - redis (~> 3.0, >= 3.0.4) - resque (1.25.2) - mono_logger (~> 1.0) - multi_json (~> 1.0) - redis-namespace (~> 1.3) - sinatra (>= 0.9.2) - vegas (~> 0.1.2) - resque-scheduler (3.0.0) - mono_logger (~> 1.0) - redis (~> 3.0) - resque (~> 1.25) - rufus-scheduler (~> 2.0) - rufus-scheduler (2.0.24) - tzinfo (>= 0.3.22) - sequel (4.8.0) - serverengine (1.5.9) - sigdump (~> 0.2.2) - sidekiq (3.2.1) - celluloid (>= 0.15.2) - connection_pool (>= 2.0.0) - json - redis (>= 3.0.6) - redis-namespace (>= 1.3.1) - sigdump (0.2.2) - sinatra (1.4.5) - rack (~> 1.4) - rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) - sneakers (0.1.1.pre) - bunny (~> 1.1.3) - serverengine - thor - thread - sprockets (2.12.1) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.1.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - sqlite3 (1.3.9) - sucker_punch (1.1) - celluloid (~> 0.15.2) - thor (0.19.1) - thread (0.1.4) - thread_safe (0.3.4) - tilt (1.4.1) - timers (1.1.0) - tzinfo (1.2.1) - thread_safe (~> 0.1) - vegas (0.1.11) - rack (>= 1.0.0) - -PLATFORMS - ruby - -DEPENDENCIES - activejob! - arel! - backburner - delayed_job - delayed_job_active_record - i18n! - qu-rails! - qu-redis - que - queue_classic - rack! - rails! - rake - resque - resque-scheduler - sequel - sidekiq - sneakers (= 0.1.1.pre) - sqlite3 - sucker_punch diff --git a/activejob/Rakefile b/activejob/Rakefile index b2910de81d..e661622165 100644 --- a/activejob/Rakefile +++ b/activejob/Rakefile @@ -1,6 +1,7 @@ -require 'bundler/gem_tasks' - require 'rake/testtask' +require 'rubygems/package_task' + +dir = File.dirname(__FILE__) def run_without_aborting(*tasks) errors = [] @@ -18,51 +19,66 @@ end task default: :test -ADAPTERS = %w(inline delayed_job qu que queue_classic resque sidekiq sneakers sucker_punch backburner) +ACTIVEJOB_ADAPTERS = %w(inline delayed_job qu que queue_classic resque sidekiq sneakers sucker_punch backburner) desc 'Run all adapter tests' task :test do - tasks = ADAPTERS.map{|a| "test_#{a}" }+["integration_test"] + tasks = ACTIVEJOB_ADAPTERS.map{|a| "test_#{a}" } run_without_aborting(*tasks) end -ADAPTERS.each do |adapter| - Rake::TestTask.new("test_#{adapter}") do |t| - t.libs << 'test' - t.test_files = FileList['test/cases/**/*_test.rb'] - t.verbose = true +namespace :test do + desc 'Run all adapter tests in isolation' + task :isolated do + tasks = ACTIVEJOB_ADAPTERS.map{|a| "isolated_test_#{a}" } + run_without_aborting(*tasks) + end +end + + +ACTIVEJOB_ADAPTERS.each do |adapter| + namespace :test do + Rake::TestTask.new(adapter => "#{adapter}:env") do |t| + t.description = "" + t.libs << 'test' + t.test_files = FileList['test/cases/**/*_test.rb'] + t.verbose = true + end + + namespace :isolated do + task adapter => "#{adapter}:env" do + Dir.glob("#{dir}/test/cases/**/*_test.rb").all? do |file| + sh(Gem.ruby, '-w', "-I#{dir}/lib", "-I#{dir}/test", file) + end or raise 'Failures' + end + end end namespace adapter do task test: "test_#{adapter}" + task isolated_test: "isolated_test_#{adapter}" + task(:env) { ENV['AJADAPTER'] = adapter } end - task "test_#{adapter}" => "#{adapter}:env" -end - + desc "Run #{adapter} tests" + task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"] -desc 'Run all adapter integration tests' -task :integration_test do - tasks = (ADAPTERS-['inline']).map{|a| "integration_test_#{a}" } - run_without_aborting(*tasks) + desc "Run #{adapter} tests in isolation" + task "isolated_test_#{adapter}" => ["#{adapter}:env", "test:isolated:#{adapter}"] end -(ADAPTERS-['inline']).each do |adapter| - Rake::TestTask.new("integration_test_#{adapter}") do |t| - t.libs << 'test' - t.test_files = FileList['test/integration/**/*_test.rb'] - t.verbose = true - end - namespace "integration_#{adapter}" do - task test: "integration_test_#{adapter}" - task(:env) do - ENV['AJADAPTER'] = adapter - ENV['AJ_INTEGRATION_TESTS'] = "1" - end - end +spec = eval(File.read('activejob.gemspec')) + +Gem::PackageTask.new(spec) do |p| + p.gem_spec = spec +end - task "integration_test_#{adapter}" => "integration_#{adapter}:env" +desc 'Release to rubygems' +task release: :package do + require 'rake/gemcutter' + Rake::Gemcutter::Tasks.new(spec).define + Rake::Task['gem:push'].invoke end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index 537702edd4..a4c010c7bd 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -1,5 +1,6 @@ require 'helper' require "active_support/log_subscriber/test_helper" +require 'jobs/hello_job' require 'jobs/logging_job' require 'jobs/nested_job' diff --git a/activejob/test/dummy/Rakefile b/activejob/test/dummy/Rakefile deleted file mode 100644 index 9866295e6a..0000000000 --- a/activejob/test/dummy/Rakefile +++ /dev/null @@ -1,3 +0,0 @@ -require 'sneakers/tasks' -require File.expand_path('../config/application', __FILE__) -Rails.application.load_tasks diff --git a/activejob/test/dummy/app/assets/images/.keep b/activejob/test/dummy/app/assets/images/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/app/controllers/application_controller.rb b/activejob/test/dummy/app/controllers/application_controller.rb deleted file mode 100644 index 1c07694e9d..0000000000 --- a/activejob/test/dummy/app/controllers/application_controller.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ApplicationController < ActionController::Base - protect_from_forgery with: :exception -end diff --git a/activejob/test/dummy/app/controllers/concerns/.keep b/activejob/test/dummy/app/controllers/concerns/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/app/helpers/application_helper.rb b/activejob/test/dummy/app/helpers/application_helper.rb deleted file mode 100644 index de6be7945c..0000000000 --- a/activejob/test/dummy/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/activejob/test/dummy/app/jobs/test_job.rb b/activejob/test/dummy/app/jobs/test_job.rb deleted file mode 100644 index 281771a851..0000000000 --- a/activejob/test/dummy/app/jobs/test_job.rb +++ /dev/null @@ -1,9 +0,0 @@ -class TestJob < ActiveJob::Base - queue_as :default - - def perform(x) - File.open(Rails.root.join("tmp/#{x}"), "w+") do |f| - f.write x - end - end -end diff --git a/activejob/test/dummy/app/mailers/.keep b/activejob/test/dummy/app/mailers/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/app/models/.keep b/activejob/test/dummy/app/models/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/app/models/concerns/.keep b/activejob/test/dummy/app/models/concerns/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/config.ru b/activejob/test/dummy/config.ru deleted file mode 100644 index 5bc2a619e8..0000000000 --- a/activejob/test/dummy/config.ru +++ /dev/null @@ -1,4 +0,0 @@ -# This file is used by Rack-based servers to start the application. - -require ::File.expand_path('../config/environment', __FILE__) -run Rails.application diff --git a/activejob/test/dummy/config/application.rb b/activejob/test/dummy/config/application.rb deleted file mode 100644 index 8b06039a68..0000000000 --- a/activejob/test/dummy/config/application.rb +++ /dev/null @@ -1,9 +0,0 @@ -require File.expand_path('../boot', __FILE__) -require 'rails/all' -Bundler.require(*Rails.groups) - -module Dummy - class Application < Rails::Application - end -end - diff --git a/activejob/test/dummy/config/boot.rb b/activejob/test/dummy/config/boot.rb deleted file mode 100644 index 6266cfc509..0000000000 --- a/activejob/test/dummy/config/boot.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) -$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/activejob/test/dummy/config/database.yml b/activejob/test/dummy/config/database.yml deleted file mode 100644 index f5f3aaf1fa..0000000000 --- a/activejob/test/dummy/config/database.yml +++ /dev/null @@ -1,3 +0,0 @@ -test: - adapter: sqlite3 - database: "db/test.sqlite3" diff --git a/activejob/test/dummy/config/environment.rb b/activejob/test/dummy/config/environment.rb deleted file mode 100644 index 7fd2f91b8f..0000000000 --- a/activejob/test/dummy/config/environment.rb +++ /dev/null @@ -1,2 +0,0 @@ -require File.expand_path('../application', __FILE__) -Rails.application.initialize! diff --git a/activejob/test/dummy/config/environments/test.rb b/activejob/test/dummy/config/environments/test.rb deleted file mode 100644 index ff0318412f..0000000000 --- a/activejob/test/dummy/config/environments/test.rb +++ /dev/null @@ -1,13 +0,0 @@ -Rails.application.configure do - config.cache_classes = true - config.eager_load = false - config.serve_static_assets = true - config.static_cache_control = 'public, max-age=3600' - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - config.action_dispatch.show_exceptions = false - config.action_controller.allow_forgery_protection = false - config.action_mailer.delivery_method = :test - config.active_support.deprecation = :stderr - config.log_level = :debug -end diff --git a/activejob/test/dummy/config/initializers/activejob.rb b/activejob/test/dummy/config/initializers/activejob.rb deleted file mode 100644 index 5fcde86c96..0000000000 --- a/activejob/test/dummy/config/initializers/activejob.rb +++ /dev/null @@ -1,65 +0,0 @@ -case ENV['AJADAPTER'] -when "delayed_job" - ActiveJob::Base.queue_adapter = :delayed_job -when "sidekiq" - ActiveJob::Base.queue_adapter = :sidekiq -when "resque" - ActiveJob::Base.queue_adapter = :resque - Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "tcp://127.0.0.1:6379/12", :thread_safe => true) - Resque.logger = Rails.logger -when 'qu' - ActiveJob::Base.queue_adapter = :qu - ENV['REDISTOGO_URL'] = "tcp://127.0.0.1:6379/12" - backend = Qu::Backend::Redis.new - backend.namespace = "active_jobs_int_test" - Qu.backend = backend - Qu.logger = Rails.logger - Qu.interval = 0.5 -when 'que' - ActiveJob::Base.queue_adapter = :que - QUE_URL = ENV['QUE_DATABASE_URL'] || 'postgres://localhost/active_jobs_que_int_test' - uri = URI.parse(QUE_URL) - user = uri.user||ENV['USER'] - pass = uri.password - db = uri.path[1..-1] - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database "#{db}"' -U #{user} -t template1} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} - Que.connection = Sequel.connect(QUE_URL) - Que.migrate! - Que.mode = :off - Que.worker_count = 1 -when 'queue_classic' - ENV['QC_DATABASE_URL'] ||= 'postgres://localhost/active_jobs_qc_int_test' - ENV['QC_LISTEN_TIME'] = "0.5" - ActiveJob::Base.queue_adapter = :queue_classic - uri = URI.parse(ENV['QC_DATABASE_URL']) - user = uri.user||ENV['USER'] - pass = uri.password - db = uri.path[1..-1] - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database "#{db}"' -U #{user} -t template1} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} - QC::Setup.create -when 'sidekiq' - ActiveJob::Base.queue_adapter = :sidekiq -when 'sneakers' - ActiveJob::Base.queue_adapter = :sneakers - Sneakers.configure :heartbeat => 2, - :amqp => 'amqp://guest:guest@localhost:5672', - :vhost => '/', - :exchange => 'active_jobs_sneakers_int_test', - :exchange_type => :direct, - :daemonize => true, - :threads => 1, - :workers => 1, - :pid_path => Rails.root.join("tmp/sneakers.pid").to_s, - :log => Rails.root.join("log/sneakers.log").to_s -when 'sucker_punch' - ActiveJob::Base.queue_adapter = :sucker_punch -when 'backburner' - ActiveJob::Base.queue_adapter = :backburner - Backburner.configure do |config| - config.logger = Rails.logger - end -else - ActiveJob::Base.queue_adapter = nil -end diff --git a/activejob/test/dummy/config/initializers/session_store.rb b/activejob/test/dummy/config/initializers/session_store.rb deleted file mode 100644 index 70a5a506a9..0000000000 --- a/activejob/test/dummy/config/initializers/session_store.rb +++ /dev/null @@ -1 +0,0 @@ -Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/activejob/test/dummy/config/routes.rb b/activejob/test/dummy/config/routes.rb deleted file mode 100644 index 1daf9a4121..0000000000 --- a/activejob/test/dummy/config/routes.rb +++ /dev/null @@ -1,2 +0,0 @@ -Rails.application.routes.draw do -end diff --git a/activejob/test/dummy/config/secrets.yml b/activejob/test/dummy/config/secrets.yml deleted file mode 100644 index 7dfacb38ea..0000000000 --- a/activejob/test/dummy/config/secrets.yml +++ /dev/null @@ -1,2 +0,0 @@ -test: - secret_key_base: b83ee5aeada663bc4270a1817d0ca43b2784017cc77dc8afcd60967cc968d4ce30caff9eb682766129e18a4048c4d5ebf14eabf463fc37ad67c18934f4345545 diff --git a/activejob/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb b/activejob/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb deleted file mode 100644 index ec0dd93ce1..0000000000 --- a/activejob/test/dummy/db/migrate/20140804200445_create_delayed_jobs.rb +++ /dev/null @@ -1,22 +0,0 @@ -class CreateDelayedJobs < ActiveRecord::Migration - def self.up - create_table :delayed_jobs, :force => true do |table| - table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue - table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually. - table.text :handler, :null => false # YAML-encoded string of the object that will do work - table.text :last_error # reason for last failure (See Note below) - table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. - table.datetime :locked_at # Set when a client is working on this object - table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) - table.string :locked_by # Who is working on this object (if locked) - table.string :queue # The name of the queue this job is in - table.timestamps - end - - add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' - end - - def self.down - drop_table :delayed_jobs - end -end diff --git a/activejob/test/dummy/db/schema.rb b/activejob/test/dummy/db/schema.rb deleted file mode 100644 index 012a099f9c..0000000000 --- a/activejob/test/dummy/db/schema.rb +++ /dev/null @@ -1,32 +0,0 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20140804200445) do - - create_table "delayed_jobs", force: true do |t| - t.integer "priority", default: 0, null: false - t.integer "attempts", default: 0, null: false - t.text "handler", null: false - t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" - t.string "locked_by" - t.string "queue" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority" - -end diff --git a/activejob/test/dummy/db/test.sqlite3 b/activejob/test/dummy/db/test.sqlite3 deleted file mode 100644 index 671e20102e..0000000000 Binary files a/activejob/test/dummy/db/test.sqlite3 and /dev/null differ diff --git a/activejob/test/dummy/lib/assets/.keep b/activejob/test/dummy/lib/assets/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/log/.keep b/activejob/test/dummy/log/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/dummy/tmp/.keep b/activejob/test/dummy/tmp/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index 104dabd861..ad263c05cd 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -6,13 +6,8 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" require 'active_job' adapter = ENV['AJADAPTER'] || 'inline' -puts "Testing#{" integration" if ENV['AJ_INTEGRATION_TESTS']} using #{adapter}" -if ENV['AJ_INTEGRATION_TESTS'] - require 'support/integration/helper' -else - require "adapters/#{adapter}" -end +require "adapters/#{adapter}" require 'active_support/testing/autorun' diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb deleted file mode 100644 index bf6137af4c..0000000000 --- a/activejob/test/integration/queuing_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'helper' -require 'jobs/logging_job' -require 'active_support/core_ext/numeric/time' - - -class QueuingTest < ActiveSupport::TestCase - setup do - - end - - test 'run queued job' do - id = "AJ-#{SecureRandom.uuid}" - TestJob.enqueue id - sleep 2 - assert Dummy::Application.root.join("tmp/#{id}").exist? - end - -end diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb deleted file mode 100644 index 7271d50a45..0000000000 --- a/activejob/test/support/integration/adapters/backburner.rb +++ /dev/null @@ -1,15 +0,0 @@ -module BackburnerJobsManager - def clear_jobs - Backburner::Worker.connection.tubes.all.map &:clear - end - - def start_workers - @thread = Thread.new { Backburner.work "active-jobs-default" } - end - - def stop_workers - @thread.kill - end - -end - diff --git a/activejob/test/support/integration/adapters/delayed_job.rb b/activejob/test/support/integration/adapters/delayed_job.rb deleted file mode 100644 index 3e55933438..0000000000 --- a/activejob/test/support/integration/adapters/delayed_job.rb +++ /dev/null @@ -1,14 +0,0 @@ -module DelayedJobJobsManager - def clear_jobs - Delayed::Job.delete_all - end - - def start_workers - @worker = Delayed::Worker.new(quiet: false, sleep_delay: 0.5) - @thread = Thread.new { @worker.start } - end - - def stop_workers - @worker.stop - end -end diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb deleted file mode 100644 index 12d063ea0d..0000000000 --- a/activejob/test/support/integration/adapters/qu.rb +++ /dev/null @@ -1,14 +0,0 @@ -module QuJobsManager - def clear_jobs - Qu.clear "active_jobs_default" - end - - def start_workers - @thread = Thread.new { Qu::Worker.new("active_jobs_default").start } - end - - def stop_workers - @thread.kill - end -end - diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb deleted file mode 100644 index f15c9af910..0000000000 --- a/activejob/test/support/integration/adapters/que.rb +++ /dev/null @@ -1,19 +0,0 @@ -module QueJobsManager - def clear_jobs - Que.clear! - end - - def start_workers - @thread = Thread.new do - loop do - Que::Job.work("active_jobs_default") - sleep 0.5 - end - end - end - - def stop_workers - @thread.kill - end -end - diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb deleted file mode 100644 index 3b24eca5b9..0000000000 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ /dev/null @@ -1,21 +0,0 @@ -module QC; WAIT_TIME = 0.5; end - -module QueueClassicJobsManager - def clear_jobs - # disabling this as it locks - # QC::Queue.new("active_jobs_default").delete_all - end - - def start_workers - @pid = fork do - QC::Conn.connection = QC::Conn.connect - worker = QC::Worker.new(q_name: 'active_jobs_default') - worker.start - end - end - - def stop_workers - Process.kill 'HUP', @pid - end -end - diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb deleted file mode 100644 index b9811bd3e1..0000000000 --- a/activejob/test/support/integration/adapters/resque.rb +++ /dev/null @@ -1,18 +0,0 @@ -module ResqueJobsManager - def clear_jobs - Resque.queues.each { |queue_name| Resque.redis.del "queue:#{queue_name}" } - Resque.redis.keys("delayed:*").each { |key| Resque.redis.del "#{key}" } - Resque.redis.del "delayed_queue_schedule" - end - - def start_workers - @thread = Thread.new do - Resque::Worker.new("*").work(0.5) - end - end - - def stop_workers - @thread.kill - end -end - diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb deleted file mode 100644 index d3b7d15614..0000000000 --- a/activejob/test/support/integration/adapters/sidekiq.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'sidekiq/launcher' -require 'sidekiq/api' - -module SidekiqJobsManager - def clear_jobs - Sidekiq::Queue.new("active_jobs_default").clear - end - - def start_workers - options = {:queues=>["active_jobs_default"], :concurrency=>1, :environment=>"test", :timeout=>8, :daemon=>true, :strict=>true} - @launcher = Sidekiq::Launcher.new(options) - @launcher.run - end - - def stop_workers - @launcher.stop - end -end - diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb deleted file mode 100644 index 5dcab68515..0000000000 --- a/activejob/test/support/integration/adapters/sneakers.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'sneakers/runner' - -module SneakersJobsManager - def clear_jobs - end - - def start_workers - cmd = %{cd #{Rails.root.to_s} && (RAILS_ENV=test AJADAPTER=sneakers WORKERS=ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper bundle exec rake --trace sneakers:run)} - `#{cmd}` - while !Rails.root.join("tmp/sneakers.pid").exist? do - sleep 0.5 - end - end - - def stop_workers - Process.kill 'TERM', File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i - end -end diff --git a/activejob/test/support/integration/adapters/sucker_punch.rb b/activejob/test/support/integration/adapters/sucker_punch.rb deleted file mode 100644 index 317f9c80fd..0000000000 --- a/activejob/test/support/integration/adapters/sucker_punch.rb +++ /dev/null @@ -1,5 +0,0 @@ -module SuckerPunchJobsManager - def clear_jobs - end -end - diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb deleted file mode 100644 index cb94e7cfb5..0000000000 --- a/activejob/test/support/integration/helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -ENV["RAILS_ENV"] = "test" -require File.expand_path("../../../dummy/config/environment.rb", __FILE__) -require "rails/test_help" -Rails.backtrace_cleaner.remove_silencers! - -require_relative 'test_case_helpers' -ActiveSupport::TestCase.send(:include, TestCaseHelpers) - -JobsManager.current_manager.setup -JobsManager.current_manager.start_workers -Minitest.after_run { JobsManager.current_manager.stop_workers } - diff --git a/activejob/test/support/integration/jobs_manager.rb b/activejob/test/support/integration/jobs_manager.rb deleted file mode 100644 index 1da74193b1..0000000000 --- a/activejob/test/support/integration/jobs_manager.rb +++ /dev/null @@ -1,23 +0,0 @@ -class JobsManager - @@managers = {} - attr :adapter_name - - def self.current_manager - @@managers[ENV['AJADAPTER']] ||= new(ENV['AJADAPTER']) - end - - def initialize(adapter_name) - @adapter_name = adapter_name - require_relative "adapters/#{adapter_name}" - extend "#{adapter_name.camelize}JobsManager".constantize - end - - def setup - end - - def start_workers - end - - def stop_workers - end -end diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb deleted file mode 100644 index 9a5eea0783..0000000000 --- a/activejob/test/support/integration/test_case_helpers.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'active_support/concern' -require 'support/integration/jobs_manager' - -module TestCaseHelpers - extend ActiveSupport::Concern - - included do - self.use_transactional_fixtures = false - - setup do - clear_jobs - end - - teardown do - clear_jobs - FileUtils.rm_rf Dir[Dummy::Application.root.join("tmp/AJ-*")] - end - end - - protected - - def jobs_manager - JobsManager.current_manager - end - - def clear_jobs - jobs_manager.clear_jobs - end - -end -- cgit v1.2.3 From 3ed69cd5f54c6eda7ee8664aa14c53205ecbb6c5 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Tue, 12 Aug 2014 13:53:46 +0300 Subject: Fixed failing tests; Load active_job in railtie; Renamed generator to job --- activejob/lib/active_job/railtie.rb | 5 +++-- .../rails/generators/active_job/job_generator.rb | 22 ---------------------- .../rails/generators/active_job/templates/job.rb | 9 --------- .../lib/rails/generators/job/job_generator.rb | 22 ++++++++++++++++++++++ .../lib/rails/generators/job/templates/job.rb | 9 +++++++++ activejob/test/cases/logging_test.rb | 1 + activejob/test/cases/queue_naming_test.rb | 4 +++- 7 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 activejob/lib/rails/generators/active_job/job_generator.rb delete mode 100644 activejob/lib/rails/generators/active_job/templates/job.rb create mode 100644 activejob/lib/rails/generators/job/job_generator.rb create mode 100644 activejob/lib/rails/generators/job/templates/job.rb (limited to 'activejob') diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 08555d1d77..16736374af 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -1,4 +1,5 @@ -require 'active_model/railtie' +require 'active_job' +require 'rails' module ActiveJob # = Active Job Railtie @@ -7,4 +8,4 @@ module ActiveJob ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger } end end -end \ No newline at end of file +end diff --git a/activejob/lib/rails/generators/active_job/job_generator.rb b/activejob/lib/rails/generators/active_job/job_generator.rb deleted file mode 100644 index fe4af0d2cc..0000000000 --- a/activejob/lib/rails/generators/active_job/job_generator.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails/generators/named_base' - -module ActiveJob - module Generators # :nodoc: - class JobGenerator < Rails::Generators::NamedBase # :nodoc: - desc 'This generator creates an active job file at app/jobs' - - class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job' - - def self.default_generator_root - File.dirname(__FILE__) - end - - check_class_collision suffix: 'Job' - - def create_job_file - template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb") - end - - end - end -end \ No newline at end of file diff --git a/activejob/lib/rails/generators/active_job/templates/job.rb b/activejob/lib/rails/generators/active_job/templates/job.rb deleted file mode 100644 index 6a21616d30..0000000000 --- a/activejob/lib/rails/generators/active_job/templates/job.rb +++ /dev/null @@ -1,9 +0,0 @@ -<% module_namespacing do -%> -class <%= class_name %>Job < ActiveJob::Base - queue_as :<%= options[:queue] %> - - def perform - # Do something later - end -end -<% end -%> \ No newline at end of file diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb new file mode 100644 index 0000000000..78a9c27606 --- /dev/null +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -0,0 +1,22 @@ +require 'rails/generators/named_base' + +module Rails + module Generators # :nodoc: + class JobGenerator < Rails::Generators::NamedBase # :nodoc: + desc 'This generator creates an active job file at app/jobs' + + class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job' + + def self.default_generator_root + File.dirname(__FILE__) + end + + check_class_collision suffix: 'Job' + + def create_job_file + template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb") + end + + end + end +end diff --git a/activejob/lib/rails/generators/job/templates/job.rb b/activejob/lib/rails/generators/job/templates/job.rb new file mode 100644 index 0000000000..6a21616d30 --- /dev/null +++ b/activejob/lib/rails/generators/job/templates/job.rb @@ -0,0 +1,9 @@ +<% module_namespacing do -%> +class <%= class_name %>Job < ActiveJob::Base + queue_as :<%= options[:queue] %> + + def perform + # Do something later + end +end +<% end -%> \ No newline at end of file diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index a4c010c7bd..3f21fa644c 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -1,5 +1,6 @@ require 'helper' require "active_support/log_subscriber/test_helper" +require 'active_support/core_ext/numeric/time' require 'jobs/hello_job' require 'jobs/logging_job' require 'jobs/nested_job' diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 852643b9f6..7cb516bbb4 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -1,11 +1,13 @@ require 'helper' require 'jobs/hello_job' +require 'jobs/logging_job' +require 'jobs/nested_job' class QueueNamingTest < ActiveSupport::TestCase test 'name derived from base' do assert_equal "active_jobs", HelloJob.queue_name end - + test 'name appended in job' do begin HelloJob.queue_as :greetings -- cgit v1.2.3 From 7c84dfb510a573fbe80a9de7064b59c381987fbb Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Tue, 12 Aug 2014 15:43:43 +0300 Subject: Update activejob's README --- activejob/README.md | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'activejob') diff --git a/activejob/README.md b/activejob/README.md index 5adb41b0b6..ebb7876c81 100644 --- a/activejob/README.md +++ b/activejob/README.md @@ -5,7 +5,7 @@ of queueing backends. These jobs can be everything from regularly scheduled clean-ups, billing charges, or mailings. Anything that can be chopped up into small units of work and run in parallel, really. -It also serves as the backend for [ActionMailer's #deliver_later functionality](https://github.com/rails/activejob/issues/13) +It also serves as the backend for ActionMailer's #deliver_later functionality that makes it easy to turn any mailing into a job for running later. That's one of the most common jobs in a modern web application: Sending emails outside of the request-response cycle, so the user doesn't have to wait on it. @@ -105,16 +105,37 @@ We currently have adapters for: * [activejob-stats](https://github.com/seuros/activejob-stats) -## Under development as a gem, targeted for Rails inclusion +## Download and installation -Active Job is currently being developed in a separate repository until it's -ready to be merged in with Rails. The current plan is to have Active Job -be part of the Rails 4.2 release, but plans may change depending on when -this framework stabilizes and feels ready. +The latest version of Active Job can be installed with RubyGems: +``` + % [sudo] gem install activejob +``` + +Source code can be downloaded as part of the Rails project on GitHub + +* https://github.com/rails/rails/tree/master/activejob ## License -Active Job is released under the MIT license: +ActiveJob is released under the MIT license: * http://www.opensource.org/licenses/MIT + + +## Support + +API documentation is at + +* http://api.rubyonrails.org + +Bug reports can be filed for the Ruby on Rails project here: + +* https://github.com/rails/rails/issues + +Feature requests should be discussed on the rails-core mailing list here: + +* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core + + -- cgit v1.2.3 From 22ee993825897fe2adafebeed57158f0699b071b Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Tue, 12 Aug 2014 15:57:57 +0300 Subject: Modified activejob.gemspec to match other rails gems format --- activejob/activejob.gemspec | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'activejob') diff --git a/activejob/activejob.gemspec b/activejob/activejob.gemspec index 23fd25c6c8..fd551e540e 100644 --- a/activejob/activejob.gemspec +++ b/activejob/activejob.gemspec @@ -1,8 +1,10 @@ +version = File.read(File.expand_path('../../RAILS_VERSION', __FILE__)).strip + Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = 'activejob' - s.version = '4.2.0.alpha' - s.summary = 'Job framework with pluggable queues (will be part of Rails).' + s.version = version + s.summary = 'Job framework with pluggable queues.' s.description = 'Declare job classes that can be run by a variety of queueing backends.' s.required_ruby_version = '>= 1.9.3' @@ -13,9 +15,9 @@ Gem::Specification.new do |s| s.email = 'david@loudthinking.com' s.homepage = 'http://www.rubyonrails.org' - s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.rdoc', 'lib/**/*'] + s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.md', 'lib/**/*'] s.require_path = 'lib' - s.add_dependency 'activesupport', '>= 4.1.0' + s.add_dependency 'activesupport', version s.add_dependency 'activemodel-globalid' end -- cgit v1.2.3 From 67f8b6b2bc7e7eca8723996b1303c3fafa5ed39b Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 12 Aug 2014 18:24:19 +0000 Subject: Added ActionMailer::DeliverLater --- activejob/lib/active_job.rb | 2 -- activejob/lib/active_job/logging.rb | 4 ++-- activejob/lib/activejob.rb | 1 - activejob/test/helper.rb | 5 +---- 4 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 activejob/lib/activejob.rb (limited to 'activejob') diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index ddfdda4fb4..f0a34ffb44 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -23,8 +23,6 @@ require 'active_support' require 'active_support/rails' - -require 'active_job/railtie' if defined?(Rails) require 'active_job/version' module ActiveJob diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index d913aee03d..d20bc3efce 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -7,7 +7,7 @@ module ActiveJob included do cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) } - around_enqueue do |job, block, _| + around_enqueue do |_, block, _| tag_logger do block.call end @@ -17,7 +17,7 @@ module ActiveJob tag_logger(job.class.name, job.job_id) do payload = {adapter: job.class.queue_adapter, job: job.class, args: job.arguments} ActiveSupport::Notifications.instrument("perform_start.active_job", payload.dup) - ActiveSupport::Notifications.instrument("perform.active_job", payload) do |payload| + ActiveSupport::Notifications.instrument("perform.active_job", payload) do block.call end end diff --git a/activejob/lib/activejob.rb b/activejob/lib/activejob.rb deleted file mode 100644 index fea38731af..0000000000 --- a/activejob/lib/activejob.rb +++ /dev/null @@ -1 +0,0 @@ -require 'active_job' diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index ad263c05cd..8e255c1696 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -1,7 +1,4 @@ -require 'bundler' -Bundler.setup - -$LOAD_PATH << File.dirname(__FILE__) + "/../lib" +require File.expand_path('../../../load_paths', __FILE__) require 'active_job' -- cgit v1.2.3 From 9b209603d07cad48b47d554407d6319c9fcced18 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Wed, 13 Aug 2014 12:57:23 +0000 Subject: Clean adapter_test.rb and skip test for sidekiq in unsupported rubies --- activejob/test/cases/adapter_test.rb | 54 ++---------------------------------- activejob/test/helper.rb | 21 ++++++++++++-- 2 files changed, 22 insertions(+), 53 deletions(-) (limited to 'activejob') diff --git a/activejob/test/cases/adapter_test.rb b/activejob/test/cases/adapter_test.rb index 7f6f4c1159..4fc235ae40 100644 --- a/activejob/test/cases/adapter_test.rb +++ b/activejob/test/cases/adapter_test.rb @@ -1,56 +1,8 @@ require 'helper' class AdapterTest < ActiveSupport::TestCase - setup { @old_adapter = ActiveJob::Base.queue_adapter } - teardown { ActiveJob::Base.queue_adapter = @old_adapter } - - test 'should load inline adapter' do - ActiveJob::Base.queue_adapter = :inline - assert_equal ActiveJob::QueueAdapters::InlineAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Delayed Job adapter' do - ActiveJob::Base.queue_adapter = :delayed_job - assert_equal ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Qu adapter' do - ActiveJob::Base.queue_adapter = :qu - assert_equal ActiveJob::QueueAdapters::QuAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Que adapter' do - ActiveJob::Base.queue_adapter = :que - assert_equal ActiveJob::QueueAdapters::QueAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Queue Classic adapter' do - ActiveJob::Base.queue_adapter = :queue_classic - assert_equal ActiveJob::QueueAdapters::QueueClassicAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Resque adapter' do - ActiveJob::Base.queue_adapter = :resque - assert_equal ActiveJob::QueueAdapters::ResqueAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Sidekiq adapter' do - ActiveJob::Base.queue_adapter = :sidekiq - assert_equal ActiveJob::QueueAdapters::SidekiqAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Sucker Punch adapter' do - ActiveJob::Base.queue_adapter = :sucker_punch - assert_equal ActiveJob::QueueAdapters::SuckerPunchAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Sneakers adapter' do - ActiveJob::Base.queue_adapter = :sneakers - assert_equal ActiveJob::QueueAdapters::SneakersAdapter, ActiveJob::Base.queue_adapter - end - - test 'should load Backburner adapter' do - ActiveJob::Base.queue_adapter = :backburner - assert_equal ActiveJob::QueueAdapters::BackburnerAdapter, ActiveJob::Base.queue_adapter + test "should load #{ENV['AJADAPTER']} adapter" do + ActiveJob::Base.queue_adapter = ENV['AJADAPTER'].to_sym + assert_equal ActiveJob::Base.queue_adapter, "active_job/queue_adapters/#{ENV['AJADAPTER']}_adapter".classify.constantize end end diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index 8e255c1696..5e491332ee 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -2,9 +2,26 @@ require File.expand_path('../../../load_paths', __FILE__) require 'active_job' -adapter = ENV['AJADAPTER'] || 'inline' +@adapter = ENV['AJADAPTER'] || 'inline' -require "adapters/#{adapter}" +def sidekiq? + @adapter == 'sidekiq' +end + +def rubinius? + RUBY_ENGINE == 'rbx' +end + +def ruby_193? + RUBY_VERSION == '1.9.3' && RUBY_ENGINE != 'java' +end + +#Sidekiq don't work with MRI 1.9.3 +#Travis uses rbx 2.6 which don't support unicode characters in methods. +#Remove the check when Travis change to rbx 2.7+ +exit if sidekiq? && (ruby_193? || rubinius?) + +require "adapters/#{@adapter}" require 'active_support/testing/autorun' -- cgit v1.2.3 From 8147e22a4d09a159a2084fb7ac5c2cfa527a9422 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Thu, 14 Aug 2014 22:54:56 +0000 Subject: Update resque_adapter.rb --- activejob/lib/active_job/queue_adapters/resque_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_adapters/resque_adapter.rb b/activejob/lib/active_job/queue_adapters/resque_adapter.rb index b228825f07..30a51485bd 100644 --- a/activejob/lib/active_job/queue_adapters/resque_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/resque_adapter.rb @@ -7,7 +7,7 @@ begin rescue LoadError begin require 'resque_scheduler' - rescue LoadError + rescue LoadError => e $stderr.puts 'The ActiveJob resque adapter requires resque-scheduler. Please add it to your Gemfile and run bundle install' raise e end -- cgit v1.2.3 From 94ae25ecd5635f7f97a2e53afa8e3f82c408435d Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Fri, 15 Aug 2014 23:32:08 +0300 Subject: ActiveJob: Reworked queue_base_name as default_queue_name + Allow configure ActiveJob from app.config.active_job --- activejob/lib/active_job/queue_name.rb | 8 ++++---- activejob/lib/active_job/railtie.rb | 14 +++++++++++++- activejob/test/cases/queue_naming_test.rb | 10 +++++----- 3 files changed, 22 insertions(+), 10 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index 859ddad034..c2186d9fe9 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -3,16 +3,16 @@ module ActiveJob extend ActiveSupport::Concern module ClassMethods - mattr_accessor(:queue_base_name) { "active_jobs" } + mattr_accessor(:default_queue_name) { "default" } def queue_as(part_name) - self.queue_name = "#{queue_base_name}_#{part_name}" + self.queue_name = part_name.to_s.presence || default_queue_name end end included do class_attribute :queue_name - self.queue_name = queue_base_name + self.queue_name = default_queue_name end end -end \ No newline at end of file +end diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 16736374af..7c1dd8f275 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -4,8 +4,20 @@ require 'rails' module ActiveJob # = Active Job Railtie class Railtie < Rails::Railtie # :nodoc: - initializer 'active_job' do + config.active_job = ActiveSupport::OrderedOptions.new + + initializer 'active_job.logger' do ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger } end + + initializer "active_job.set_configs" do |app| + options = app.config.active_job + options.queue_adapter ||= :inline + + ActiveSupport.on_load(:active_job) do + options.each { |k,v| send("#{k}=", v) } + end + end + end end diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 7cb516bbb4..426af608f0 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -5,7 +5,7 @@ require 'jobs/nested_job' class QueueNamingTest < ActiveSupport::TestCase test 'name derived from base' do - assert_equal "active_jobs", HelloJob.queue_name + assert_equal "default", HelloJob.queue_name end test 'name appended in job' do @@ -13,11 +13,11 @@ class QueueNamingTest < ActiveSupport::TestCase HelloJob.queue_as :greetings LoggingJob.queue_as :bookkeeping - assert_equal "active_jobs", NestedJob.queue_name - assert_equal "active_jobs_greetings", HelloJob.queue_name - assert_equal "active_jobs_bookkeeping", LoggingJob.queue_name + assert_equal "default", NestedJob.queue_name + assert_equal "greetings", HelloJob.queue_name + assert_equal "bookkeeping", LoggingJob.queue_name ensure - HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.queue_base_name + HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.default_queue_name end end end -- cgit v1.2.3 From c2f1eca19409cbbe72bf89b2087b212341201aa1 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Fri, 15 Aug 2014 23:35:06 +0300 Subject: Suggest the perform method can take arguments when generating an ActiveJob job --- activejob/lib/rails/generators/job/templates/job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/rails/generators/job/templates/job.rb b/activejob/lib/rails/generators/job/templates/job.rb index 6a21616d30..462c71d917 100644 --- a/activejob/lib/rails/generators/job/templates/job.rb +++ b/activejob/lib/rails/generators/job/templates/job.rb @@ -2,8 +2,8 @@ class <%= class_name %>Job < ActiveJob::Base queue_as :<%= options[:queue] %> - def perform + def perform(*args) # Do something later end end -<% end -%> \ No newline at end of file +<% end -%> -- cgit v1.2.3 From 788aee5acf195d55914e086540f907d9291e9d24 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sat, 16 Aug 2014 00:02:06 +0300 Subject: Moved AR testing from using global variable to thread variable --- activejob/test/cases/job_serialization_test.rb | 4 ++-- activejob/test/cases/logging_test.rb | 2 +- activejob/test/cases/queuing_test.rb | 10 +++++----- activejob/test/cases/rescue_test.rb | 4 ++-- activejob/test/jobs/gid_job.rb | 4 ++-- activejob/test/jobs/hello_job.rb | 2 +- activejob/test/jobs/rescue_job.rb | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'activejob') diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index b1e24db22e..f3b89d8899 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -4,12 +4,12 @@ require 'models/person' class JobSerializationTest < ActiveSupport::TestCase setup do - $BUFFER = [] + Thread.current[:ajbuffer] = [] @person = Person.find(5) end test 'serialize job with gid' do GidJob.enqueue @person - assert_equal "Person with ID: 5", $BUFFER.pop + assert_equal "Person with ID: 5", Thread.current[:ajbuffer].pop end end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index 3f21fa644c..f0f315c906 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -23,7 +23,7 @@ class AdapterTest < ActiveSupport::TestCase def setup super - $BUFFER = [] + Thread.current[:ajbuffer] = [] @old_logger = ActiveJob::Base.logger @logger = ActiveSupport::TaggedLogging.new(TestLogger.new) set_logger @logger diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index 3dd9ecd8d2..49760ce9c0 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -5,17 +5,17 @@ require 'active_support/core_ext/numeric/time' class QueuingTest < ActiveSupport::TestCase setup do - $BUFFER = [] + Thread.current[:ajbuffer] = [] end test 'run queued job' do HelloJob.enqueue - assert_equal "David says hello", $BUFFER.pop + assert_equal "David says hello", Thread.current[:ajbuffer].pop end test 'run queued job with arguments' do HelloJob.enqueue "Jamie" - assert_equal "Jamie says hello", $BUFFER.pop + assert_equal "Jamie says hello", Thread.current[:ajbuffer].pop end test 'run queued job later' do @@ -26,13 +26,13 @@ class QueuingTest < ActiveSupport::TestCase skip end end - + test 'job returned by enqueue has the arguments available' do job = HelloJob.enqueue "Jamie" assert_equal [ "Jamie" ], job.arguments end - + test 'job returned by enqueue_at has the timestamp available' do begin job = HelloJob.enqueue_at Time.utc(2014, 1, 1) diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb index 3d4831bc62..4fbd27fe6c 100644 --- a/activejob/test/cases/rescue_test.rb +++ b/activejob/test/cases/rescue_test.rb @@ -5,13 +5,13 @@ require 'active_support/core_ext/object/inclusion' class RescueTest < ActiveSupport::TestCase setup do - $BUFFER = [] + Thread.current[:ajbuffer] = [] end test 'rescue perform exception with retry' do job = RescueJob.new job.execute(SecureRandom.uuid, "david") - assert_equal [ "rescued from ArgumentError", "performed beautifully" ], $BUFFER + assert_equal [ "rescued from ArgumentError", "performed beautifully" ], Thread.current[:ajbuffer] end test 'let through unhandled perform exception' do diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb index c69e38d3cc..eeb34c8a87 100644 --- a/activejob/test/jobs/gid_job.rb +++ b/activejob/test/jobs/gid_job.rb @@ -1,6 +1,6 @@ class GidJob < ActiveJob::Base def perform(person) - $BUFFER << "Person with ID: #{person.id}" + Thread.current[:ajbuffer] << "Person with ID: #{person.id}" end end - \ No newline at end of file + diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb index 25441dd0c8..cb067bbe69 100644 --- a/activejob/test/jobs/hello_job.rb +++ b/activejob/test/jobs/hello_job.rb @@ -1,5 +1,5 @@ class HelloJob < ActiveJob::Base def perform(greeter = "David") - $BUFFER << "#{greeter} says hello" + Thread.current[:ajbuffer] << "#{greeter} says hello" end end diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb index acf2b81515..e42de4876e 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -2,7 +2,7 @@ class RescueJob < ActiveJob::Base class OtherError < StandardError; end rescue_from(ArgumentError) do - $BUFFER << "rescued from ArgumentError" + Thread.current[:ajbuffer] << "rescued from ArgumentError" arguments[0] = "DIFFERENT!" retry_now end @@ -14,7 +14,7 @@ class RescueJob < ActiveJob::Base when "other" raise OtherError else - $BUFFER << "performed beautifully" + Thread.current[:ajbuffer] << "performed beautifully" end end end -- cgit v1.2.3 From b2cabb7aceac9e2db0a9cc4fea8a4ef50d4ea132 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sat, 16 Aug 2014 01:31:39 +0300 Subject: Added docs for AJ::Callbacks; Added AJ to docs build map --- activejob/lib/active_job/callbacks.rb | 112 ++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index c69e4a3b55..af92031bc9 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -1,40 +1,144 @@ require 'active_support/callbacks' module ActiveJob + # = Active Job Callbacks + # + # Active Job provides hooks during the lifecycle of a job. Callbacks allows you to trigger + # logic during the lifecycle of a job. Available callbacks: + # + # * before_enqueue + # * around_enqueue + # * after_enqueue + # * before_perform + # * around_perform + # * after_perform + # module Callbacks extend ActiveSupport::Concern include ActiveSupport::Callbacks - + included do define_callbacks :perform define_callbacks :enqueue end - + module ClassMethods + # Defines a callback that will get called right before the + # job's perform method is executed. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # before_perform do |job| + # UserMailer.notify_video_started_processing(job.arguments.first) + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def before_perform(*filters, &blk) set_callback(:perform, :before, *filters, &blk) end + # Defines a callback that will get called right after the + # job's perform method has finished. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # after_perform do |job| + # UserMailer.notify_video_processed(job.arguments.first) + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def after_perform(*filters, &blk) set_callback(:perform, :after, *filters, &blk) end + # Defines a callback that will get called around the job's perform method. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # around_perform do |job, block| + # UserMailer.notify_video_started_processing(job.arguments.first) + # block.call + # UserMailer.notify_video_processed(job.arguments.first) + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def around_perform(*filters, &blk) set_callback(:perform, :around, *filters, &blk) end - + # Defines a callback that will get called right before the + # job is enqueued. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # before_enqueue do |job| + # $statsd.increment "enqueue-video-job.try" + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def before_enqueue(*filters, &blk) set_callback(:enqueue, :before, *filters, &blk) end + # Defines a callback that will get called right after the + # job is enqueued. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # after_enqueue do |job| + # $statsd.increment "enqueue-video-job.success" + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def after_enqueue(*filters, &blk) set_callback(:enqueue, :after, *filters, &blk) end + # Defines a callback that will get called before and after the + # job is enqueued. + # + # class VideoProcessJob < ActiveJob::Base + # queue_as :default + # + # around_enqueue do |job, block| + # $statsd.time "video-job.process" do + # block.call + # end + # end + # + # def perform(video_id) + # Video.find(video_id).process + # end + # end + # def around_enqueue(*filters, &blk) set_callback(:enqueue, :around, *filters, &blk) end end end -end \ No newline at end of file +end -- cgit v1.2.3 From fdc7dbc5b239f44243b9a973197ca7c031bc6313 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 15 Aug 2014 09:50:45 +0000 Subject: [ActiveJob] require files in logging.rb --- activejob/lib/active_job/logging.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activejob') diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index d20bc3efce..d9e544acf5 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -1,4 +1,6 @@ require 'active_support/core_ext/string/filters' +require 'active_support/tagged_logging' +require 'active_support/logger' module ActiveJob module Logging -- cgit v1.2.3 From 3954fdf5f325719143df12860f65d778350d12ed Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 15 Aug 2014 10:04:06 +0000 Subject: [ActiveJob] Convert ActiveJob::Arguments into module --- activejob/lib/active_job/arguments.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index ef6a3fce1d..8486a9e918 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -2,19 +2,20 @@ require 'active_model/global_locator' require 'active_model/global_identification' module ActiveJob - class Arguments + module Arguments + extend self TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] - def self.serialize(arguments) + def serialize(arguments) arguments.map { |argument| serialize_argument(argument) } end - def self.deserialize(arguments) + def deserialize(arguments) arguments.map { |argument| deserialize_argument(argument) } end private - def self.serialize_argument(argument) + def serialize_argument(argument) case argument when ActiveModel::GlobalIdentification argument.global_id.to_s @@ -29,7 +30,7 @@ module ActiveJob end end - def self.deserialize_argument(argument) + def deserialize_argument(argument) case argument when Array deserialize(argument) @@ -40,7 +41,7 @@ module ActiveJob end end - def self.serialize_hash_key(key) + def serialize_hash_key(key) case key when String, Symbol key.to_s -- cgit v1.2.3 From b06d91924ffeb07c5ca6a3d96eff288267ee80c6 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 15 Aug 2014 10:11:58 +0000 Subject: [ActiveJob] remove ruby warnings --- activejob/lib/active_job/enqueuing.rb | 2 +- activejob/lib/active_job/execution.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index e3ac11ba97..c00aab40da 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -57,7 +57,7 @@ module ActiveJob end def retry_now - self.class.enqueue *arguments + self.class.enqueue(*arguments) end def retry_in(interval) diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index 78ada3d908..181d049616 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -14,14 +14,14 @@ module ActiveJob self.arguments = Arguments.deserialize(serialized_args) run_callbacks :perform do - perform *arguments + perform(*arguments) end rescue => exception rescue_with_handler(exception) || raise(exception) end def perform(*) - raise NotImplementedError + fail NotImplementedError end end end -- cgit v1.2.3 From 59221cc4f1b8f87553455aad26905c4f28b424f8 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sat, 16 Aug 2014 15:49:03 +0300 Subject: [ActiveJob] make the resque-scheduler optional --- activejob/lib/active_job/queue_adapters/resque_adapter.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_adapters/resque_adapter.rb b/activejob/lib/active_job/queue_adapters/resque_adapter.rb index 30a51485bd..384aa0c4cc 100644 --- a/activejob/lib/active_job/queue_adapters/resque_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/resque_adapter.rb @@ -7,9 +7,8 @@ begin rescue LoadError begin require 'resque_scheduler' - rescue LoadError => e - $stderr.puts 'The ActiveJob resque adapter requires resque-scheduler. Please add it to your Gemfile and run bundle install' - raise e + rescue LoadError + false end end @@ -22,6 +21,10 @@ module ActiveJob end def enqueue_at(job, timestamp, *args) + unless Resque.respond_to?(:enqueue_at_with_queue) + raise NotImplementedError, "To be able to schedule jobs with Resque you need the " \ + "resque-scheduler gem. Please add it to your Gemfile and run bundle install" + end Resque.enqueue_at_with_queue job.queue_name, timestamp, JobWrapper, job.name, *args end end -- cgit v1.2.3 From 2f7b239fca6630e49ba8ad9df6fc7db25e1080f0 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 17 Aug 2014 01:06:30 +0000 Subject: [ActiveJob] Use globalid gem --- activejob/README.md | 4 ++-- activejob/activejob.gemspec | 3 +-- activejob/lib/active_job.rb | 1 + activejob/lib/active_job/arguments.rb | 7 ++----- activejob/lib/active_job/enqueuing.rb | 2 +- activejob/test/helper.rb | 2 ++ activejob/test/models/person.rb | 4 +--- 7 files changed, 10 insertions(+), 13 deletions(-) (limited to 'activejob') diff --git a/activejob/README.md b/activejob/README.md index ebb7876c81..e48070bcfc 100644 --- a/activejob/README.md +++ b/activejob/README.md @@ -59,7 +59,7 @@ That's it! ## GlobalID support -Active Job supports [GlobalID serialization](https://github.com/rails/activemodel-globalid/) for parameters. This makes it possible +Active Job supports [GlobalID serialization](https://github.com/rails/globalid/) for parameters. This makes it possible to pass live Active Record objects to your job instead of class/id pairs, which you then have to manually deserialize. Before, jobs would look like this: @@ -82,7 +82,7 @@ class TrashableCleanupJob end ``` -This works with any class that mixes in ActiveModel::GlobalIdentification, which +This works with any class that mixes in GlobalID::Identification, which by default has been mixed into Active Record classes. diff --git a/activejob/activejob.gemspec b/activejob/activejob.gemspec index fd551e540e..d609bb8fce 100644 --- a/activejob/activejob.gemspec +++ b/activejob/activejob.gemspec @@ -18,6 +18,5 @@ Gem::Specification.new do |s| s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.md', 'lib/**/*'] s.require_path = 'lib' - s.add_dependency 'activesupport', version - s.add_dependency 'activemodel-globalid' + s.add_dependency 'globalid' end diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index f0a34ffb44..ef92406725 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -24,6 +24,7 @@ require 'active_support' require 'active_support/rails' require 'active_job/version' +require 'global_id' module ActiveJob extend ActiveSupport::Autoload diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index 8486a9e918..b7572b0e29 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -1,6 +1,3 @@ -require 'active_model/global_locator' -require 'active_model/global_identification' - module ActiveJob module Arguments extend self @@ -17,7 +14,7 @@ module ActiveJob private def serialize_argument(argument) case argument - when ActiveModel::GlobalIdentification + when GlobalID::Identification argument.global_id.to_s when *TYPE_WHITELIST argument @@ -37,7 +34,7 @@ module ActiveJob when Hash Hash[ argument.map { |key, value| [ key, deserialize_argument(value) ] } ].with_indifferent_access else - ActiveModel::GlobalLocator.locate(argument) || argument + GlobalID::Locator.locate(argument) || argument end end diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index c00aab40da..3d00d51867 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -7,7 +7,7 @@ module ActiveJob module ClassMethods # Push a job onto the queue. The arguments must be legal JSON types # (string, int, float, nil, true, false, hash or array) or - # ActiveModel::GlobalIdentication instances. Arbitrary Ruby objects + # GlobalID::Identification instances. Arbitrary Ruby objects # are not supported. # # Returns an instance of the job class queued with args available in diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index 5e491332ee..a56b35da12 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -2,6 +2,8 @@ require File.expand_path('../../../load_paths', __FILE__) require 'active_job' +GlobalID.app = 'aj' + @adapter = ENV['AJADAPTER'] || 'inline' def sidekiq? diff --git a/activejob/test/models/person.rb b/activejob/test/models/person.rb index a5bdbc462b..b31396db4b 100644 --- a/activejob/test/models/person.rb +++ b/activejob/test/models/person.rb @@ -1,7 +1,5 @@ -require 'active_model/global_identification' - class Person - include ActiveModel::GlobalIdentification + include GlobalID::Identification attr_reader :id -- cgit v1.2.3 From 931cfc40796bfd2f4638d8ca7a11723d7562e9cd Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 17 Aug 2014 13:23:24 +0000 Subject: [ActiveJob] Fix tests for sucker_punch --- activejob/test/cases/job_serialization_test.rb | 4 ++-- activejob/test/cases/logging_test.rb | 2 +- activejob/test/cases/queuing_test.rb | 6 +++--- activejob/test/cases/rescue_test.rb | 4 ++-- activejob/test/helper.rb | 20 ++++++++++++++++++++ activejob/test/jobs/gid_job.rb | 2 +- activejob/test/jobs/hello_job.rb | 2 +- activejob/test/jobs/rescue_job.rb | 4 ++-- 8 files changed, 32 insertions(+), 12 deletions(-) (limited to 'activejob') diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index f3b89d8899..fc1b77744c 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -4,12 +4,12 @@ require 'models/person' class JobSerializationTest < ActiveSupport::TestCase setup do - Thread.current[:ajbuffer] = [] + JobBuffer.clear @person = Person.find(5) end test 'serialize job with gid' do GidJob.enqueue @person - assert_equal "Person with ID: 5", Thread.current[:ajbuffer].pop + assert_equal "Person with ID: 5", JobBuffer.last_value end end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index f0f315c906..888c183a0b 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -23,7 +23,7 @@ class AdapterTest < ActiveSupport::TestCase def setup super - Thread.current[:ajbuffer] = [] + JobBuffer.clear @old_logger = ActiveJob::Base.logger @logger = ActiveSupport::TaggedLogging.new(TestLogger.new) set_logger @logger diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index 49760ce9c0..f020316d7e 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -5,17 +5,17 @@ require 'active_support/core_ext/numeric/time' class QueuingTest < ActiveSupport::TestCase setup do - Thread.current[:ajbuffer] = [] + JobBuffer.clear end test 'run queued job' do HelloJob.enqueue - assert_equal "David says hello", Thread.current[:ajbuffer].pop + assert_equal "David says hello", JobBuffer.last_value end test 'run queued job with arguments' do HelloJob.enqueue "Jamie" - assert_equal "Jamie says hello", Thread.current[:ajbuffer].pop + assert_equal "Jamie says hello", JobBuffer.last_value end test 'run queued job later' do diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb index 4fbd27fe6c..250ab68671 100644 --- a/activejob/test/cases/rescue_test.rb +++ b/activejob/test/cases/rescue_test.rb @@ -5,13 +5,13 @@ require 'active_support/core_ext/object/inclusion' class RescueTest < ActiveSupport::TestCase setup do - Thread.current[:ajbuffer] = [] + JobBuffer.clear end test 'rescue perform exception with retry' do job = RescueJob.new job.execute(SecureRandom.uuid, "david") - assert_equal [ "rescued from ArgumentError", "performed beautifully" ], Thread.current[:ajbuffer] + assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values end test 'let through unhandled perform exception' do diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index a56b35da12..ca67700273 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -28,3 +28,23 @@ require "adapters/#{@adapter}" require 'active_support/testing/autorun' ActiveJob::Base.logger.level = Logger::DEBUG + +module JobBuffer + class << self + def clear + @buffer = [] + end + + def add(value) + @buffer << value + end + + def values + @buffer + end + + def last_value + @buffer.last + end + end +end diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb index eeb34c8a87..35c2366ec4 100644 --- a/activejob/test/jobs/gid_job.rb +++ b/activejob/test/jobs/gid_job.rb @@ -1,6 +1,6 @@ class GidJob < ActiveJob::Base def perform(person) - Thread.current[:ajbuffer] << "Person with ID: #{person.id}" + JobBuffer.add("Person with ID: #{person.id}") end end diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb index cb067bbe69..4c6256af0d 100644 --- a/activejob/test/jobs/hello_job.rb +++ b/activejob/test/jobs/hello_job.rb @@ -1,5 +1,5 @@ class HelloJob < ActiveJob::Base def perform(greeter = "David") - Thread.current[:ajbuffer] << "#{greeter} says hello" + JobBuffer.add("#{greeter} says hello") end end diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb index e42de4876e..77084160d9 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -2,7 +2,7 @@ class RescueJob < ActiveJob::Base class OtherError < StandardError; end rescue_from(ArgumentError) do - Thread.current[:ajbuffer] << "rescued from ArgumentError" + JobBuffer.add('rescued from ArgumentError') arguments[0] = "DIFFERENT!" retry_now end @@ -14,7 +14,7 @@ class RescueJob < ActiveJob::Base when "other" raise OtherError else - Thread.current[:ajbuffer] << "performed beautifully" + JobBuffer.add('performed beautifully') end end end -- cgit v1.2.3 From 9a3426220145cf8862324f204eece64f3a6a4634 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 17 Aug 2014 19:16:43 +0000 Subject: [ActiveJob] Add deserialize_arguments method to job --- activejob/lib/active_job/execution.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index 181d049616..0e7b5bdd72 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -11,7 +11,7 @@ module ActiveJob def execute(job_id, *serialized_args) self.job_id = job_id - self.arguments = Arguments.deserialize(serialized_args) + self.arguments = deserialize_arguments(serialized_args) run_callbacks :perform do perform(*arguments) @@ -23,5 +23,11 @@ module ActiveJob def perform(*) fail NotImplementedError end + + private + def deserialize_arguments(serialized_args) + Arguments.deserialize(serialized_args) + end + end end -- cgit v1.2.3 From 3faa61ede58aa29400e4e062a799c61913ae213f Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sun, 17 Aug 2014 23:48:44 +0300 Subject: [ActiveJob] raise DeserializationError when got an error deserializing --- activejob/lib/active_job/arguments.rb | 12 ++++++++++++ activejob/test/cases/rescue_test.rb | 7 +++++++ activejob/test/jobs/rescue_job.rb | 5 +++++ activejob/test/models/person.rb | 3 +++ 4 files changed, 27 insertions(+) (limited to 'activejob') diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index b7572b0e29..369e716912 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -1,4 +1,14 @@ module ActiveJob + class DeserializationError < StandardError + attr_reader :original_exception + + def initialize(e) + super ("Error while trying to deserialize arguments: #{e.message}") + @original_exception = e + set_backtrace e.backtrace + end + end + module Arguments extend self TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] @@ -36,6 +46,8 @@ module ActiveJob else GlobalID::Locator.locate(argument) || argument end + rescue => e + raise DeserializationError.new(e) end def serialize_hash_key(key) diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb index 250ab68671..c9473314f2 100644 --- a/activejob/test/cases/rescue_test.rb +++ b/activejob/test/cases/rescue_test.rb @@ -20,4 +20,11 @@ class RescueTest < ActiveSupport::TestCase job.execute(SecureRandom.uuid, "other") end end + + test 'rescue from deserialization errors' do + RescueJob.enqueue Person.new(404) + assert_includes JobBuffer.values, 'rescued from DeserializationError' + assert_includes JobBuffer.values, 'DeserializationError original exception was Person::RecordNotFound' + assert_not_includes JobBuffer.values, 'performed beautifully' + end end diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb index 77084160d9..e9cb37d1c4 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -7,6 +7,11 @@ class RescueJob < ActiveJob::Base retry_now end + rescue_from(ActiveJob::DeserializationError) do |e| + JobBuffer.add('rescued from DeserializationError') + JobBuffer.add("DeserializationError original exception was #{e.original_exception.class.name}") + end + def perform(person = "david") case person when "david" diff --git a/activejob/test/models/person.rb b/activejob/test/models/person.rb index b31396db4b..76a8f40616 100644 --- a/activejob/test/models/person.rb +++ b/activejob/test/models/person.rb @@ -1,9 +1,12 @@ class Person + class RecordNotFound < StandardError; end + include GlobalID::Identification attr_reader :id def self.find(id) + raise RecordNotFound.new("Cannot find person with ID=404") if id.to_i==404 new(id) end -- cgit v1.2.3 From 080296be61105f4f941441a506a6a9fe5c562772 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 17 Aug 2014 23:17:38 +0000 Subject: [ActiveJob] require global_id/railtie --- activejob/lib/active_job/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 7c1dd8f275..6538ac1b30 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -1,5 +1,5 @@ +require 'global_id/railtie' require 'active_job' -require 'rails' module ActiveJob # = Active Job Railtie -- cgit v1.2.3