arsenicum 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/arsenicum.gemspec +5 -0
  4. data/bin/arsenicum +1 -7
  5. data/lib/arsenicum.rb +23 -12
  6. data/lib/arsenicum/async.rb +3 -0
  7. data/lib/arsenicum/async/queue.rb +37 -0
  8. data/lib/arsenicum/async/queue/sqs.rb +27 -0
  9. data/lib/arsenicum/configuration.rb +114 -63
  10. data/lib/arsenicum/core.rb +6 -0
  11. data/lib/arsenicum/core/broker.rb +98 -0
  12. data/lib/arsenicum/core/commands.rb +15 -0
  13. data/lib/arsenicum/core/io_helper.rb +34 -0
  14. data/lib/arsenicum/core/worker.rb +91 -0
  15. data/lib/arsenicum/formatter.rb +127 -0
  16. data/lib/arsenicum/io.rb +3 -0
  17. data/lib/arsenicum/main.rb +23 -0
  18. data/lib/arsenicum/routing.rb +3 -0
  19. data/lib/arsenicum/routing/default.rb +3 -0
  20. data/lib/arsenicum/serializer.rb +3 -0
  21. data/lib/arsenicum/serializer/json.rb +11 -0
  22. data/lib/arsenicum/task.rb +10 -50
  23. data/lib/arsenicum/task/class_dispatcher.rb +15 -0
  24. data/lib/arsenicum/util.rb +48 -0
  25. data/lib/arsenicum/version.rb +1 -1
  26. data/lib/generators/arsenicum/migration/migration_generator.rb +32 -0
  27. data/lib/generators/arsenicum/migration/templates/active_record/migration.rb +15 -0
  28. data/spec/arsenicum/queueing/post_office_spec.rb +123 -0
  29. data/spec/arsenicum/queueing/serializer_spec.rb +70 -0
  30. data/spec/config/config.example.yml +22 -0
  31. data/spec/config/post_office_spec.yml +24 -0
  32. data/spec/rails_project/.gitignore +16 -0
  33. data/spec/rails_project/Gemfile +45 -0
  34. data/spec/rails_project/README.rdoc +28 -0
  35. data/spec/rails_project/Rakefile +6 -0
  36. data/spec/rails_project/app/assets/images/.keep +0 -0
  37. data/spec/rails_project/app/assets/javascripts/application.js +16 -0
  38. data/spec/rails_project/app/assets/stylesheets/application.css +13 -0
  39. data/spec/rails_project/app/controllers/application_controller.rb +5 -0
  40. data/spec/rails_project/app/controllers/concerns/.keep +0 -0
  41. data/spec/rails_project/app/helpers/application_helper.rb +2 -0
  42. data/spec/rails_project/app/mailers/.keep +0 -0
  43. data/spec/rails_project/app/models/.keep +0 -0
  44. data/spec/rails_project/app/models/concerns/.keep +0 -0
  45. data/spec/rails_project/app/models/sample.rb +2 -0
  46. data/spec/rails_project/app/views/layouts/application.html.erb +14 -0
  47. data/spec/rails_project/bin/bundle +3 -0
  48. data/spec/rails_project/bin/rails +4 -0
  49. data/spec/rails_project/bin/rake +4 -0
  50. data/spec/rails_project/config.ru +4 -0
  51. data/spec/rails_project/config/application.rb +23 -0
  52. data/spec/rails_project/config/boot.rb +4 -0
  53. data/spec/rails_project/config/database.yml +25 -0
  54. data/spec/rails_project/config/environment.rb +5 -0
  55. data/spec/rails_project/config/environments/development.rb +29 -0
  56. data/spec/rails_project/config/environments/production.rb +80 -0
  57. data/spec/rails_project/config/environments/test.rb +36 -0
  58. data/spec/rails_project/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/rails_project/config/initializers/filter_parameter_logging.rb +4 -0
  60. data/spec/rails_project/config/initializers/inflections.rb +16 -0
  61. data/spec/rails_project/config/initializers/mime_types.rb +5 -0
  62. data/spec/rails_project/config/initializers/secret_token.rb +12 -0
  63. data/spec/rails_project/config/initializers/session_store.rb +3 -0
  64. data/spec/rails_project/config/initializers/wrap_parameters.rb +14 -0
  65. data/spec/rails_project/config/locales/en.yml +23 -0
  66. data/spec/rails_project/config/routes.rb +56 -0
  67. data/spec/rails_project/db/migrate/20131210025434_create_samples.rb +9 -0
  68. data/spec/rails_project/db/schema.rb +22 -0
  69. data/spec/rails_project/db/seeds.rb +7 -0
  70. data/spec/rails_project/lib/assets/.keep +0 -0
  71. data/spec/rails_project/lib/tasks/.keep +0 -0
  72. data/spec/rails_project/log/.keep +0 -0
  73. data/spec/rails_project/public/404.html +58 -0
  74. data/spec/rails_project/public/422.html +58 -0
  75. data/spec/rails_project/public/500.html +57 -0
  76. data/spec/rails_project/public/favicon.ico +0 -0
  77. data/spec/rails_project/public/robots.txt +5 -0
  78. data/spec/rails_project/test/controllers/.keep +0 -0
  79. data/spec/rails_project/test/helpers/.keep +0 -0
  80. data/spec/rails_project/test/integration/.keep +0 -0
  81. data/spec/rails_project/test/mailers/.keep +0 -0
  82. data/spec/rails_project/test/test_helper.rb +15 -0
  83. data/spec/rails_project/vendor/assets/javascripts/.keep +0 -0
  84. data/spec/rails_project/vendor/assets/stylesheets/.keep +0 -0
  85. data/spec/spec_helper.rb +5 -0
  86. metadata +217 -27
  87. data/lib/arsenicum/actor.rb +0 -14
  88. data/lib/arsenicum/cli.rb +0 -54
  89. data/lib/arsenicum/cli/rails.rb +0 -26
  90. data/lib/arsenicum/queue.rb +0 -58
  91. data/lib/arsenicum/queue_proxy.rb +0 -73
  92. data/lib/arsenicum/rake_tasks.rake +0 -24
  93. data/lib/arsenicum/serialization.rb +0 -110
  94. data/lib/arsenicum/server.rb +0 -40
  95. data/lib/arsenicum/sqs.rb +0 -5
  96. data/lib/arsenicum/sqs/queue.rb +0 -76
  97. data/lib/arsenicum/syntax.rb +0 -11
  98. data/lib/arsenicum/syntax/delayed_job.rb +0 -25
  99. data/lib/arsenicum/watchdog.rb +0 -68
  100. data/spec/config.example.yml +0 -21
@@ -1,3 +1,3 @@
1
1
  module Arsenicum
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,32 @@
1
+ class Arsenicum::MigrationGenerator
2
+ include Rails::Generators::Migration
3
+
4
+ def self.orm
5
+ Rails::Generators.options[:rails][:orm]
6
+ end
7
+ def self.source_root
8
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
9
+ end
10
+
11
+ def self.orm_has_migration?
12
+ [:active_record].include? orm
13
+ end
14
+
15
+ def self.next_migration_number(dirname)
16
+ if ActiveRecord::Base.timestamped_migrations
17
+ migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
18
+ migration_number += 1
19
+ migration_number.to_s
20
+ else
21
+ "%.3d" % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+
25
+ desc "This generator provides the tables which the Arsenicum uses."
26
+ def create_migration_file
27
+ if self.class.orm_has_migration?
28
+ migration_template 'migration.rb', 'db/migrate/create_arsenicum_queues'
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,15 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :j7w1_application_devices do |t|
4
+ t.string :owner_type, null: false
5
+ t.integer :owner_id, null: false
6
+ t.string :device_identifier, null: false
7
+ t.string :platform, null: false
8
+ t.string :device_endpoint_arn, null: true
9
+ t.boolean :disabled, null: false, default: false
10
+
11
+ t.index [:owner_type, :owner_id]
12
+ t.index [:device_identifier, :platform], unique: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+ require 'yaml'
3
+
4
+ class SampleA;end
5
+ class SampleB;end
6
+ class Default;end
7
+
8
+ describe Arsenicum::Queueing::PostOffice do
9
+
10
+ subject do
11
+ yaml_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config/post_office_spec.yml'))
12
+ yaml_values = YAML.load(File.read(yaml_path, encoding: 'UTF-8'))
13
+ Arsenicum::Configuration.new(yaml_values['development']).post_office
14
+ end
15
+
16
+ describe :deliver_to do
17
+ shared_examples_for :correct_delivery do
18
+ let(:result){subject.queues[queue_name].receive}
19
+ let(:request_object) do
20
+ Arsenicum::Queueing::Request.new target: task[:worker], method_name: task[:method], arguments: task[:arguments]
21
+ end
22
+
23
+ before{subject.post request_object}
24
+
25
+ specify{expect(result).to include(:id)}
26
+ specify{expect(result[:body]).to eq(request_object.serialize)}
27
+ end
28
+
29
+ describe 'class method invocation' do
30
+ context do
31
+ let(:task){
32
+ {
33
+ worker: SampleB,
34
+ method: :hoge2,
35
+ arguments: [1]
36
+ }
37
+ }
38
+ let(:queue_name){:sample01}
39
+ it_should_behave_like :correct_delivery
40
+ end
41
+ context '' do
42
+ let(:task){
43
+ {
44
+ worker: SampleB,
45
+ method: :hoge1,
46
+ arguments: [1]
47
+ }
48
+ }
49
+ let(:queue_name){:sample_b}
50
+ it_should_behave_like :correct_delivery
51
+ end
52
+ context do
53
+ let(:task){
54
+ {
55
+ worker: SampleA,
56
+ method: :hoge1,
57
+ arguments: [1]
58
+ }
59
+ }
60
+ let(:queue_name){:sample_a}
61
+ it_should_behave_like :correct_delivery
62
+ end
63
+ context 'fallback to default' do
64
+ let(:task){
65
+ {
66
+ worker: Default,
67
+ method: :hoge1,
68
+ arguments: [1]
69
+ }
70
+ }
71
+ let(:queue_name){:default}
72
+ it_should_behave_like :correct_delivery
73
+ end
74
+ end
75
+
76
+ describe 'instance method invocation' do
77
+ context do
78
+ let(:task){
79
+ {
80
+ worker: SampleB.new,
81
+ method: :hoge2,
82
+ arguments: [1]
83
+ }
84
+ }
85
+ let(:queue_name){:sample02}
86
+ it_should_behave_like :correct_delivery
87
+ end
88
+ context '' do
89
+ let(:task){
90
+ {
91
+ worker: SampleB.new,
92
+ method: :hoge1,
93
+ arguments: [1]
94
+ }
95
+ }
96
+ let(:queue_name){:sample_b}
97
+ it_should_behave_like :correct_delivery
98
+ end
99
+ context do
100
+ let(:task){
101
+ {
102
+ worker: SampleA.new,
103
+ method: :hoge1,
104
+ arguments: [1]
105
+ }
106
+ }
107
+ let(:queue_name){:sample01}
108
+ it_should_behave_like :correct_delivery
109
+ end
110
+ context 'fallback to default' do
111
+ let(:task){
112
+ {
113
+ worker: Default.new,
114
+ method: :hoge1,
115
+ arguments: [1]
116
+ }
117
+ }
118
+ let(:queue_name){:default}
119
+ it_should_behave_like :correct_delivery
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,70 @@
1
+ require 'date'
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
4
+
5
+ describe Arsenicum::Queueing::Serializer do
6
+ subject{Object.new.extend(Arsenicum::Queueing::Serializer)}
7
+
8
+ describe [:serialize_object, :restore_object] do
9
+
10
+ shared_examples_for :serialize_restore do
11
+ specify{expect(subject.restore_object subject.serialize_object worker).to eq(worker)}
12
+ end
13
+
14
+ context :target_is_raw do
15
+ shared_examples_for :raw_object do
16
+ specify{expect(subject.serialize_object worker).to eq({type: 'raw', value: worker.inspect})}
17
+ it_should_behave_like :serialize_restore
18
+ end
19
+
20
+ context :target_is_integer do
21
+ let(:worker){1}
22
+ it_should_behave_like :raw_object
23
+ end
24
+
25
+ context :target_is_float do
26
+ let(:worker){1.3}
27
+ it_should_behave_like :raw_object
28
+ end
29
+
30
+ context :target_is_string do
31
+ let(:worker){"string"}
32
+ it_should_behave_like :raw_object
33
+ end
34
+
35
+ context :target_is_true do
36
+ let(:worker){true}
37
+ it_should_behave_like :raw_object
38
+ end
39
+
40
+ context :target_is_false do
41
+ let(:worker){false}
42
+ it_should_behave_like :raw_object
43
+ end
44
+
45
+ context :target_is_nil do
46
+ let(:worker){nil}
47
+ it_should_behave_like :raw_object
48
+ end
49
+
50
+ end
51
+
52
+ context :time_like do
53
+ shared_examples_for :date_time do
54
+ let(:worker){target_type.now}
55
+ specify{expect(subject.serialize_object worker).to eq({type: 'datetime', value: worker.strftime('%Y-%m-%dT%H:%M:%S %Z %z')})}
56
+ specify{expect(subject.restore_object(subject.serialize_object worker).to_i).to eq(worker.to_time.to_i)}
57
+ end
58
+
59
+ context :target_is_datetime do
60
+ let(:target_type){DateTime}
61
+ it_should_behave_like :date_time
62
+ end
63
+
64
+ context :target_is_time do
65
+ let(:target_type){Time}
66
+ it_should_behave_like :date_time
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,22 @@
1
+ development:
2
+ engine: sqs
3
+ queues:
4
+ default:
5
+ concurrency: 10
6
+ sample01:
7
+ concurrency: 3
8
+ methods:
9
+ - 'SampleA#hoge1'
10
+ - 'SampleB.hoge2'
11
+ classes:
12
+ - 'ClassInvocation1'
13
+ sample02:
14
+ concurrency: 2
15
+ methods:
16
+ - 'SampleA#hoge2'
17
+ - 'SampleB.hoge1'
18
+ sqs:
19
+ account:
20
+ access_key_id: 'YOUR_ACCESS_KEY_ID'
21
+ secret_access_key: 'YOUR SECRET ACCESS KEY'
22
+ region: 'ap-northeast-1'
@@ -0,0 +1,24 @@
1
+ development:
2
+ engine: mock
3
+ log_file: '/dev/null'
4
+ queues:
5
+ default:
6
+ concurrency: 10
7
+ sample01:
8
+ concurrency: 3
9
+ methods:
10
+ - 'SampleA#hoge1'
11
+ - 'SampleB.hoge2'
12
+ sample02:
13
+ concurrency: 2
14
+ methods:
15
+ - 'SampleA#hoge2'
16
+ - 'SampleB#hoge2'
17
+ sample_a:
18
+ concurrency: 3
19
+ classes:
20
+ - SampleA
21
+ sample_b:
22
+ concurrency: 2
23
+ classes:
24
+ - SampleB
@@ -0,0 +1,16 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1,45 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
+ gem 'rails', '4.0.2'
5
+
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+
9
+ # Use SCSS for stylesheets
10
+ gem 'sass-rails', '~> 4.0.0'
11
+
12
+ # Use Uglifier as compressor for JavaScript assets
13
+ gem 'uglifier', '>= 1.3.0'
14
+
15
+ # Use CoffeeScript for .js.coffee assets and views
16
+ gem 'coffee-rails', '~> 4.0.0'
17
+
18
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
19
+ # gem 'therubyracer', platforms: :ruby
20
+
21
+ # Use jquery as the JavaScript library
22
+ gem 'jquery-rails'
23
+
24
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
25
+ gem 'turbolinks'
26
+
27
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
28
+ gem 'jbuilder', '~> 1.2'
29
+
30
+ group :doc do
31
+ # bundle exec rake doc:rails generates the API under doc/api.
32
+ gem 'sdoc', require: false
33
+ end
34
+
35
+ # Use ActiveModel has_secure_password
36
+ # gem 'bcrypt-ruby', '~> 3.1.2'
37
+
38
+ # Use unicorn as the app server
39
+ # gem 'unicorn'
40
+
41
+ # Use Capistrano for deployment
42
+ # gem 'capistrano', group: :development
43
+
44
+ # Use debugger
45
+ # gem 'debugger', group: [:development, :test]
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ ArsenicumSample::Application.load_tasks
@@ -0,0 +1,16 @@
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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= 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
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end