request_repeater 0.1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/bin/console +14 -0
- data/bin/run +6 -0
- data/bin/setup +8 -0
- data/docker/Dockerfile +10 -0
- data/docker/Gemfile +4 -0
- data/docker/Gemfile.lock +0 -0
- data/exe/request_repeater +6 -0
- data/lib/request_repeater/endpoint.rb +57 -0
- data/lib/request_repeater/request_maker.rb +47 -0
- data/lib/request_repeater/version.rb +3 -0
- data/lib/request_repeater.rb +47 -0
- data/request_repeater.gemspec +30 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68a959ff4dd248589c04be2298424b8b970de9d7
|
4
|
+
data.tar.gz: a8ceba00f49e35ab310f2c811cab65a1ed826e2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4f4527470aaa8167ffffcfcd58e7b791b3c738723574c03fb8f1bc3adb2ce0225d5c929c6cc9eef1d7415ec9887a8d7673df5fbd18288a0d489de76499d76a2
|
7
|
+
data.tar.gz: 22d4707c438acd36627c521bdf5ba515c78f0b9e8a24ca8c9bad371717c67b04eed8b1646e2c475ed0d050e3fac0bec773fb5a8b07bb47e95deddc313fce1cad
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at equivalent@eq8.eu. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tomas Valent
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Request Repeater
|
2
|
+
|
3
|
+
Simple [Ruby Gem]() or [Docker image](https://hub.docker.com/) to
|
4
|
+
execute GET request on an endpoint (Request Repeater).
|
5
|
+
|
6
|
+
This is usefull if you cannot do cron jobs in your application settup.
|
7
|
+
|
8
|
+
Just expose a certain route in your web application to execute the job
|
9
|
+
(or to schedule backround job) tell `request_repeeter` to trigger GET requests on it.
|
10
|
+
|
11
|
+
## Standalone Ruby gem
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'request_repeater'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install request_repeater
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install request_repeater
|
30
|
+
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
35
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "request_repeater"
|
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
|
data/bin/run
ADDED
data/bin/setup
ADDED
data/docker/Dockerfile
ADDED
data/docker/Gemfile
ADDED
data/docker/Gemfile.lock
ADDED
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module RequestRepeater
|
2
|
+
class Endpoint
|
3
|
+
NoEndpointToCall = Class.new(StandardError)
|
4
|
+
InvalidURL = Class.new(StandardError)
|
5
|
+
|
6
|
+
attr_reader :sleepfor
|
7
|
+
attr_writer :timer
|
8
|
+
attr_accessor :last_execution
|
9
|
+
|
10
|
+
def initialize(url:, sleepfor:)
|
11
|
+
@sleepfor = sleepfor.to_i
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
if executable?
|
17
|
+
yield
|
18
|
+
executed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def executable?
|
23
|
+
timer.now > last_execution + RequestRepeater.sleeptime(sleepfor)
|
24
|
+
end
|
25
|
+
|
26
|
+
def executed
|
27
|
+
@last_execution = timer.now
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other_endpoint)
|
31
|
+
self.url == other_endpoint.url \
|
32
|
+
&& self.sleepfor == other_endpoint.sleepfor \
|
33
|
+
&& self.last_execution == other_endpoint.last_execution
|
34
|
+
end
|
35
|
+
|
36
|
+
def timer
|
37
|
+
@timer ||= Time
|
38
|
+
end
|
39
|
+
|
40
|
+
def url
|
41
|
+
@url || raise(NoEndpointToCall)
|
42
|
+
end
|
43
|
+
|
44
|
+
def uri
|
45
|
+
@uri ||= begin
|
46
|
+
uri = URI.parse(url)
|
47
|
+
raise InvalidURL, "#{url} is not valid url. Expecting format 'http://myapp/endpoint" unless uri.host
|
48
|
+
uri.path = uri.path.to_s == '' ? '/' : uri.path
|
49
|
+
uri
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
"#<#{self.class}:#{object_id.to_s(16)} url=#{url.to_s[0..16]}... sleepfor=#{sleepfor}>"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module RequestRepeater
|
2
|
+
class RequestMaker
|
3
|
+
InvalidURL = Class.new(StandardError)
|
4
|
+
|
5
|
+
attr_reader :endpoints
|
6
|
+
attr_writer :sleeper
|
7
|
+
|
8
|
+
def initialize(endpoints)
|
9
|
+
@endpoints = endpoints
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
loop do
|
14
|
+
endpoints.each do |e|
|
15
|
+
e.execute do
|
16
|
+
request(e.uri)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
sleeper.call(minimum_sleep)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def request(uri)
|
25
|
+
req = Net::HTTP::Get.new(uri)
|
26
|
+
|
27
|
+
Net::HTTP.start(uri.host, uri.port,
|
28
|
+
:use_ssl => uri.scheme == 'https',
|
29
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
30
|
+
https.request(req)
|
31
|
+
end
|
32
|
+
.tap {|res| log_response(uri.to_s, res) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_response(url, res)
|
36
|
+
RequestRepeater.logger.info "request #{url} #{res}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def minimum_sleep
|
40
|
+
RequestRepeater.sleeptime((ENV['MINIMUMSLEEP'] || 500).to_i)
|
41
|
+
end
|
42
|
+
|
43
|
+
def sleeper
|
44
|
+
@sleeper ||= ->(sleepfor) { sleep sleepfor }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "request_repeater/version"
|
2
|
+
require 'request_repeater/endpoint'
|
3
|
+
require 'request_repeater/request_maker'
|
4
|
+
require 'uri'
|
5
|
+
require 'logger'
|
6
|
+
require 'json'
|
7
|
+
require 'net/http'
|
8
|
+
|
9
|
+
module RequestRepeater
|
10
|
+
def self.sleeptime(miliseconds)
|
11
|
+
miliseconds / 1000.0
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.logger
|
15
|
+
@logger ||= Logger.new(STDOUT)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.logger=(logger)
|
19
|
+
@logger = logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.run
|
23
|
+
if ENV['URL']
|
24
|
+
endpoints = [Endpoint.new(url: ENV['URL'], sleepfor: ENV['SLEEPFOR'] || self._default_sleep)]
|
25
|
+
elsif ENV['URLS']
|
26
|
+
endpoints = _json_to_endpoints(ENV['URLS'])
|
27
|
+
else
|
28
|
+
raise ArgumentError, 'You must specify URL or URLS envirement variable'
|
29
|
+
end
|
30
|
+
|
31
|
+
endpoints.each { |e| e.executed }
|
32
|
+
|
33
|
+
RequestRepeater::RequestMaker.new(endpoints).run
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def self._json_to_endpoints(json_string)
|
38
|
+
JSON
|
39
|
+
.parse(json_string)
|
40
|
+
.fetch('urls')
|
41
|
+
.map { |url_options| Endpoint.new(url: url_options.fetch('url'), sleepfor: url_options['sleepfor'] || url_options['sleep'] || self._default_sleep) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self._default_sleep
|
45
|
+
1000
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'request_repeater/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "request_repeater"
|
8
|
+
spec.version = RequestRepeater::VERSION
|
9
|
+
spec.authors = ["Tomas Valent"]
|
10
|
+
spec.email = ["equivalent@eq8.eu"]
|
11
|
+
|
12
|
+
spec.summary = %q{Request repeater on an endpoint}
|
13
|
+
spec.description = "Gem is a standalone Ruby executable app that will repeet " +
|
14
|
+
"GET requests to an endopoints in given timeout " +
|
15
|
+
"(e.g.: `URL=https://nginx/schedule SLEEPFOR=2000 bundle exec request_repeter` " +
|
16
|
+
" will do GET https://nginx/schedule every 2 seconds)"
|
17
|
+
spec.homepage = ""
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
29
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: request_repeater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Valent
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.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.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
description: 'Gem is a standalone Ruby executable app that will repeet GET requests
|
84
|
+
to an endopoints in given timeout (e.g.: `URL=https://nginx/schedule SLEEPFOR=2000
|
85
|
+
bundle exec request_repeter` will do GET https://nginx/schedule every 2 seconds)'
|
86
|
+
email:
|
87
|
+
- equivalent@eq8.eu
|
88
|
+
executables:
|
89
|
+
- request_repeater
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- bin/console
|
101
|
+
- bin/run
|
102
|
+
- bin/setup
|
103
|
+
- docker/Dockerfile
|
104
|
+
- docker/Gemfile
|
105
|
+
- docker/Gemfile.lock
|
106
|
+
- exe/request_repeater
|
107
|
+
- lib/request_repeater.rb
|
108
|
+
- lib/request_repeater/endpoint.rb
|
109
|
+
- lib/request_repeater/request_maker.rb
|
110
|
+
- lib/request_repeater/version.rb
|
111
|
+
- request_repeater.gemspec
|
112
|
+
homepage: ''
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.5.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Request repeater on an endpoint
|
136
|
+
test_files: []
|