rising_dragon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7325e85d2051315672725f40105ce0b5ac4e8e1
4
+ data.tar.gz: 92bc9da34ecd6182a4c1f7cae5039f5bdb3d140a
5
+ SHA512:
6
+ metadata.gz: df030940e4d67f959e4b1c4c3a9ee492e658c0693d5b45914ee10579299e27fdb8bc63d799d0223d3412d4456390f57cc11a42bd5c9ac438e902ff22d11b08d0
7
+ data.tar.gz: dadd90d5e35e6b2a30545b2d3bb5d008d75bafaf4374c624ec94ade46c337f70b11d2059303f439c95ec7833f967fb533ed5cc7a1e72dfdcb122c6786ce7a1d5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ota42y@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rising_dragon.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # RisingDragon
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rising_dragon`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rising_dragon'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rising_dragon
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'rising_dragon'
27
+ require 'securerandom'
28
+
29
+ class StepEventHandler < ::RisingDragon::SQS::Handler
30
+ def handle(event)
31
+ puts event.type
32
+ puts event.data
33
+ puts event.id
34
+ puts event.timestamp
35
+ end
36
+ end
37
+
38
+ class SQSWorker
39
+ include RisingDragon::SQS::Worker
40
+
41
+ rising_dragon_options queue: "test", auto_delete: true
42
+
43
+ def self.register_handlers(emitter)
44
+ emitter.register "StepEvent", StepEventHandler
45
+ emitter.ignore "RequlEvent"
46
+ end
47
+ end
48
+
49
+ body_hash = {
50
+ Message: {
51
+ type: "StepEvent",
52
+ data: {
53
+ "id": 42,
54
+ "datetime": DateTime.new(2016, 04, 01, 16, 00, 00, "+09:00")
55
+ },
56
+ id: SecureRandom.uuid,
57
+ timestamp: (Time.now.to_f * 1000).to_i
58
+ }
59
+ }
60
+
61
+ SQSWorker.new.perform("msg", body_hash.to_json)
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ota42y/rising_dragon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
73
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rising_dragon'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require 'rising_dragon/version'
2
+ require 'rising_dragon/event'
3
+ require 'rising_dragon/sqs/emitter'
4
+ require 'rising_dragon/sqs/handler'
5
+ require 'rising_dragon/sqs/worker'
6
+
7
+ module RisingDragon
8
+ end
@@ -0,0 +1,11 @@
1
+ module RisingDragon
2
+ class Event
3
+ attr_reader :id, :type, :timestamp, :data
4
+ def initialize(id:, type:, timestamp:, data:)
5
+ @id = id
6
+ @type = type
7
+ @timestamp = timestamp
8
+ @data = data
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ require 'json'
2
+
3
+ module RisingDragon
4
+ module SQS
5
+ class Emitter
6
+ def initialize
7
+ @handlers = {}
8
+ end
9
+
10
+ def register(event_name, handler_class)
11
+ unless event_name.is_a?(String)
12
+ raise "event_name must be String, but it's #{event_name.class}. event_name: #{event_name}"
13
+ end
14
+ if @handlers[event_name]
15
+ raise "RisingDragon::SQS::Emitter accepts only one callback per event. event_name: #{event_name}"
16
+ end
17
+ @handlers[event_name] = handler_class
18
+ end
19
+
20
+ def unregister(event_name)
21
+ unless event_name.is_a?(String)
22
+ raise "event_name must be String, but it's #{event_name.class}. event_name: #{event_name}"
23
+ end
24
+
25
+ @handlers.delete(event_name)
26
+ end
27
+
28
+ def ignore(event_name)
29
+ @handlers.delete(event_name)
30
+ end
31
+
32
+ def list
33
+ @handlers.keys
34
+ end
35
+
36
+ def emit_event(event)
37
+ handler = @handlers[event.type]
38
+ unless handler
39
+ raise "RisingDragon::SQS::Emitter handler is not registered. event_name: #{event.type}"
40
+ end
41
+
42
+ handler.new.handle(event)
43
+ nil
44
+ end
45
+
46
+ def event_from_json(json_text)
47
+ json = JSON.parse(json_text)
48
+ msg = json['Message']
49
+
50
+ id = msg['id']
51
+ type = msg['type']
52
+ timestamp = Time.at(msg['timestamp'] / 1000.0)
53
+ data = msg['data']
54
+
55
+ ::RisingDragon::Event.new(id: id, type: type, timestamp: timestamp, data: data)
56
+ end
57
+
58
+ def emit_sns_msg(body)
59
+ event = event_from_json(body)
60
+ emit_event(event)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ module RisingDragon
2
+ module SQS
3
+ class Handler
4
+ def handle(_event)
5
+ # overwrite here :)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'shoryuken'
2
+
3
+ module RisingDragon
4
+ module SQS
5
+ module Worker
6
+ def self.included(base)
7
+ base.class_eval do
8
+ include Shoryuken::Worker
9
+ end
10
+ base.extend(ClassMethods)
11
+ end
12
+
13
+ module ClassMethods
14
+ def rising_dragon_options(opt = {})
15
+ shoryuken_options(opt)
16
+ end
17
+
18
+ def register_handlers(_emitter)
19
+ raise 'Overwrite self.register_handlers'
20
+ end
21
+
22
+ def emitter
23
+ return @emitter if @emitter
24
+
25
+ @emitter = ::RisingDragon::SQS::Emitter.new
26
+ register_handlers(@emitter)
27
+ @emitter
28
+ end
29
+ end
30
+
31
+ def perform(_sqs_msg, body)
32
+ self.class.emitter.emit_sns_msg(body)
33
+ rescue => e
34
+ rescue_from(e)
35
+ end
36
+
37
+ def rescue_from(e)
38
+ # overwrite here
39
+ raise e
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module RisingDragon
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rising_dragon/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rising_dragon'
9
+ spec.version = RisingDragon::VERSION
10
+ spec.authors = ['ota42y']
11
+ spec.email = ['ota42y@gmail.com']
12
+
13
+ spec.summary = 'Event driven architecture library for AWS SNS/SQS'
14
+ spec.homepage = 'https://github.com/ota42y/rising_dragon'
15
+ spec.description = 'Event driven architecture library for AWS SNS/SQS include SQS worker and SNS publisher'
16
+ spec.license = 'MIT'
17
+
18
+ if spec.respond_to?(:metadata)
19
+ # allow push to any host
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'shoryuken', '~> 0'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.14'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'pry', '~> 0'
37
+ spec.add_development_dependency 'pry-byebug', '~> 0'
38
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rising_dragon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ota42y
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoryuken
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Event driven architecture library for AWS SNS/SQS include SQS worker
84
+ and SNS publisher
85
+ email:
86
+ - ota42y@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/rising_dragon.rb
99
+ - lib/rising_dragon/event.rb
100
+ - lib/rising_dragon/sqs/emitter.rb
101
+ - lib/rising_dragon/sqs/handler.rb
102
+ - lib/rising_dragon/sqs/worker.rb
103
+ - lib/rising_dragon/version.rb
104
+ - rising_dragon.gemspec
105
+ homepage: https://github.com/ota42y/rising_dragon
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.11
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Event driven architecture library for AWS SNS/SQS
129
+ test_files: []