qwirk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/History.md +5 -0
  2. data/lib/qwirk.rb +51 -10
  3. data/lib/qwirk/adapter/base/expanding_worker_config.rb +31 -18
  4. data/lib/qwirk/adapter/base/worker_config.rb +34 -11
  5. data/lib/qwirk/adapter/in_memory/publisher.rb +1 -1
  6. data/lib/qwirk/adapter/in_memory/queue.rb +27 -29
  7. data/lib/qwirk/adapter/in_memory/topic.rb +10 -12
  8. data/lib/qwirk/adapter/in_memory/worker.rb +9 -0
  9. data/lib/qwirk/adapter/in_memory/worker_config.rb +4 -0
  10. data/lib/qwirk/adapter/inline/worker.rb +4 -0
  11. data/lib/qwirk/adapter/inline/worker_config.rb +4 -0
  12. data/lib/qwirk/adapter_factory.rb +5 -1
  13. data/lib/qwirk/base_worker.rb +1 -5
  14. data/lib/qwirk/engine.rb +2 -6
  15. data/lib/qwirk/manager.rb +18 -10
  16. data/lib/qwirk/marshal_strategy/json.rb +1 -1
  17. data/lib/qwirk/remote_exception.rb +9 -1
  18. data/lib/qwirk/task.rb +61 -44
  19. data/lib/qwirk/worker.rb +16 -7
  20. data/test/dummy/README.rdoc +261 -0
  21. data/test/dummy/Rakefile +1 -1
  22. data/test/dummy/app/assets/javascripts/application.js +15 -0
  23. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  24. data/test/dummy/app/views/layouts/application.html.erb +3 -3
  25. data/test/dummy/config/application.rb +22 -8
  26. data/test/dummy/config/database.yml +3 -0
  27. data/test/dummy/config/environments/development.rb +15 -4
  28. data/test/dummy/config/environments/production.rb +31 -13
  29. data/test/dummy/config/environments/test.rb +9 -7
  30. data/test/dummy/config/initializers/inflections.rb +5 -0
  31. data/test/dummy/config/initializers/secret_token.rb +1 -1
  32. data/test/dummy/config/initializers/session_store.rb +1 -1
  33. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/test/dummy/config/locales/en.yml +1 -1
  35. data/test/dummy/config/routes.rb +2 -56
  36. data/test/dummy/public/500.html +0 -1
  37. data/test/dummy/script/rails +1 -1
  38. data/test/fixtures/qwirk/jobs.yml +11 -0
  39. data/test/functional/qwirk/jobs_controller_test.rb +9 -0
  40. data/test/{base_test.rb → models/base_worker_test.rb} +1 -4
  41. data/test/models/marshal_strategy_test.rb +61 -0
  42. data/test/{unit → models}/qwirk/batch/acquire_file_strategy_test.rb +0 -0
  43. data/test/{unit → models}/qwirk/batch/active_record/batch_job_test.rb +0 -0
  44. data/test/{unit → models}/qwirk/batch/parse_file_strategy_test.rb +0 -0
  45. data/test/test_helper.rb +7 -4
  46. data/test/unit/helpers/qwirk/jobs_helper_test.rb +6 -0
  47. data/test/unit/qwirk/job_test.rb +9 -0
  48. metadata +179 -117
  49. data/lib/qwirk/task.rb.sav +0 -194
  50. data/test/dummy/log/development.log +0 -0
  51. data/test/dummy/log/production.log +0 -0
  52. data/test/dummy/log/server.log +0 -0
  53. data/test/dummy/log/test.log +0 -0
  54. data/test/dummy/public/javascripts/application.js +0 -2
  55. data/test/dummy/public/javascripts/controls.js +0 -965
  56. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  57. data/test/dummy/public/javascripts/effects.js +0 -1123
  58. data/test/dummy/public/javascripts/prototype.js +0 -6001
  59. data/test/dummy/public/javascripts/rails.js +0 -191
  60. data/test/marshal_strategy_test.rb +0 -62
@@ -1,7 +1,7 @@
1
+ #!/usr/bin/env rake
1
2
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
3
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
4
 
4
5
  require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -2,9 +2,9 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
10
 
@@ -1,10 +1,6 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require "active_model/railtie"
4
- require "active_record/railtie"
5
- require "action_controller/railtie"
6
- require "action_view/railtie"
7
- require "action_mailer/railtie"
3
+ require 'rails/all'
8
4
 
9
5
  Bundler.require
10
6
  require "qwirk"
@@ -33,13 +29,31 @@ module Dummy
33
29
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
30
  # config.i18n.default_locale = :de
35
31
 
36
- # JavaScript files you want as :defaults (application.js is always included).
37
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
-
39
32
  # Configure the default encoding used in templates for Ruby 1.9.
40
33
  config.encoding = "utf-8"
41
34
 
42
35
  # Configure sensitive parameters which will be filtered from the log file.
43
36
  config.filter_parameters += [:password]
37
+
38
+ # Enable escaping HTML in JSON.
39
+ config.active_support.escape_html_entities_in_json = true
40
+
41
+ # Use SQL instead of Active Record's schema dumper when creating the database.
42
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
43
+ # like if you have constraints or database-specific column types
44
+ # config.active_record.schema_format = :sql
45
+
46
+ # Enforce whitelist mode for mass assignment.
47
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
48
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
+ # parameters by using an attr_accessible or attr_protected declaration.
50
+ config.active_record.whitelist_attributes = true
51
+
52
+ # Enable the asset pipeline
53
+ config.assets.enabled = true
54
+
55
+ # Version of your assets, change this if you want to expire all your assets
56
+ config.assets.version = '1.0'
44
57
  end
45
58
  end
59
+
@@ -1,5 +1,8 @@
1
1
  # SQLite version 3.x
2
2
  # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
3
6
  development:
4
7
  adapter: sqlite3
5
8
  database: db/development.sqlite3
@@ -2,8 +2,8 @@ Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
9
  # Log error messages when you accidentally call methods on nil.
@@ -11,7 +11,6 @@ Dummy::Application.configure do
11
11
 
12
12
  # Show full error reports and disable caching
13
13
  config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
14
  config.action_controller.perform_caching = false
16
15
 
17
16
  # Don't care if the mailer can't send
@@ -22,5 +21,17 @@ Dummy::Application.configure do
22
21
 
23
22
  # Only use best-standards-support built into browsers
24
23
  config.action_dispatch.best_standards_support = :builtin
25
- end
26
24
 
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end
@@ -1,7 +1,6 @@
1
1
  Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
- # The production environment is meant for finished, "live" apps.
5
4
  # Code is not reloaded between requests
6
5
  config.cache_classes = true
7
6
 
@@ -9,31 +8,46 @@ Dummy::Application.configure do
9
8
  config.consider_all_requests_local = false
10
9
  config.action_controller.perform_caching = true
11
10
 
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
+ # config.assets.manifest = YOUR_PATH
14
25
 
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
17
29
 
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
20
32
 
21
33
  # See everything in the log (default is :info)
22
34
  # config.log_level = :debug
23
35
 
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
24
39
  # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
26
41
 
27
42
  # Use a different cache store in production
28
43
  # config.cache_store = :mem_cache_store
29
44
 
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
35
46
  # config.action_controller.asset_host = "http://assets.example.com"
36
47
 
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
37
51
  # Disable delivery errors, bad email addresses will be ignored
38
52
  # config.action_mailer.raise_delivery_errors = false
39
53
 
@@ -46,4 +60,8 @@ Dummy::Application.configure do
46
60
 
47
61
  # Send deprecation notices to registered listeners
48
62
  config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
49
67
  end
@@ -2,12 +2,16 @@ Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
5
+ # test suite. You never need to work with it otherwise. Remember that
6
6
  # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
7
+ # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Log error messages when you accidentally call methods on nil.
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
11
15
  config.whiny_nils = true
12
16
 
13
17
  # Show full error reports and disable caching
@@ -25,10 +29,8 @@ Dummy::Application.configure do
25
29
  # ActionMailer::Base.deliveries array.
26
30
  config.action_mailer.delivery_method = :test
27
31
 
28
- # Use SQL instead of Active Record's schema dumper when creating the test database.
29
- # This is necessary if your schema can't be completely dumped by the schema dumper,
30
- # like if you have constraints or database-specific column types
31
- # config.active_record.schema_format = :sql
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
32
34
 
33
35
  # Print deprecation notices to the stderr
34
36
  config.active_support.deprecation = :stderr
@@ -8,3 +8,8 @@
8
8
  # inflect.irregular 'person', 'people'
9
9
  # inflect.uncountable %w( fish sheep )
10
10
  # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = 'f12fb952461450ff9a377ccd4ce01d3af219394efef18ce7544e8e85b8b5c2b6626caf0eef0a6f11e667c9ddccaae54f211f3947341deb2d55213de5ca6d05fa'
7
+ Dummy::Application.config.secret_token = 'c0d7138e57b353db9b6afe9174bbd7c903a432a2bb320926bbee6b7026b3e12a667b0150fc62876828426ffa5f73b9861bcb447de3af8dfd5c9bbc633a21a05d'
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -1,5 +1,5 @@
1
1
  # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
5
  hello: "Hello world"
@@ -1,58 +1,4 @@
1
- Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
1
+ Rails.application.routes.draw do
4
2
 
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => "welcome#index"
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id(.:format)))'
3
+ mount Qwirk::Engine => "/qwirk"
58
4
  end
@@ -20,7 +20,6 @@
20
20
  <!-- This file lives in public/500.html -->
21
21
  <div class="dialog">
22
22
  <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
23
  </div>
25
24
  </body>
26
25
  </html>
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env jruby
1
+ #!/usr/bin/env ruby
2
2
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
3
 
4
4
  APP_PATH = File.expand_path('../../config/application', __FILE__)
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ status: MyString
5
+ host: MyString
6
+ queue: MyString
7
+
8
+ two:
9
+ status: MyString
10
+ host: MyString
11
+ queue: MyString
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Qwirk
4
+ class JobsControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -1,7 +1,4 @@
1
- require 'qwirk'
2
- require 'shoulda'
3
- require 'test/unit'
4
- require 'fileutils'
1
+ require File.expand_path('../../test_helper', __FILE__)
5
2
 
6
3
  class DummyWorker
7
4
  include Qwirk::BaseWorker
@@ -0,0 +1,61 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class Klass
4
+ def initialize(str)
5
+ @str = str
6
+ end
7
+ def hello
8
+ @str
9
+ end
10
+ end
11
+
12
+ module SpockMarshalStrategy
13
+ extend self
14
+
15
+ def marshal_type
16
+ :text
17
+ end
18
+
19
+ def to_sym
20
+ :spock
21
+ end
22
+
23
+ # Change days to hours
24
+ def marshal(i)
25
+ (i.to_i * 24).to_s
26
+ end
27
+
28
+ # Change hours to days
29
+ def unmarshal(str)
30
+ str.to_i / 24
31
+ end
32
+
33
+ Qwirk::MarshalStrategy.register(self)
34
+ end
35
+
36
+ describe Qwirk::MarshalStrategy, 'test the various marshaling strategies and the homegrown spock one' do
37
+ before do
38
+ @bson = Qwirk::MarshalStrategy.find(:bson)
39
+ @json = Qwirk::MarshalStrategy.find(:json)
40
+ @none = Qwirk::MarshalStrategy.find(:none)
41
+ @ruby = Qwirk::MarshalStrategy.find(:ruby)
42
+ @string = Qwirk::MarshalStrategy.find(:string)
43
+ @yaml = Qwirk::MarshalStrategy.find(:yaml)
44
+ @spock = Qwirk::MarshalStrategy.find(:spock)
45
+ end
46
+
47
+ it 'should marshal and unmarshal correctly' do
48
+ hash = {'foo' => 42, 'bar' => 'zulu'}
49
+ str = 'abcdef1234'
50
+ obj = Klass.new('hello')
51
+ i = 6
52
+ @bson.unmarshal(@bson.marshal(hash)).must_equal hash
53
+ @json.unmarshal(@json.marshal(hash)).must_equal hash
54
+ @none.unmarshal(@none.marshal(hash)).must_equal hash
55
+ @ruby.unmarshal(@ruby.marshal(hash)).must_equal hash
56
+ @yaml.unmarshal(@yaml.marshal(hash)).must_equal hash
57
+ @string.unmarshal(@string.marshal(str)).must_equal str
58
+ @ruby.unmarshal(@ruby.marshal(obj)).hello.must_equal obj.hello
59
+ @spock.unmarshal(@spock.marshal(i)).must_equal i
60
+ end
61
+ end