aws_cron 0.1.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/LICENSE.md +21 -0
- data/README.md +89 -0
- data/lib/aws_cron.rb +8 -0
- data/lib/aws_cron/configuration.rb +26 -0
- data/lib/aws_cron/controller.rb +43 -0
- data/lib/aws_cron/exception_handler.rb +6 -0
- data/lib/aws_cron/identity.rb +22 -0
- data/lib/aws_cron/logger.rb +7 -0
- data/lib/aws_cron/runner.rb +26 -0
- data/lib/tasks/reek.rake +8 -0
- data/lib/tasks/rspec.rake +8 -0
- data/lib/tasks/rubocop.rake +8 -0
- metadata +212 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88227d9707b558a66849fbceb6c225d9fee670ad
|
4
|
+
data.tar.gz: 98dd86126cd1ae0510f19e7705e173723ee440d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f5cd9edf9b232fa8821b4aface5b11a82dd3025c395c2f9c216c96741370dfcb549c7c1a69b869f4c5bcbefcf674b70fc5a46cabbcf3efd3cd50504eb77878a2
|
7
|
+
data.tar.gz: 6b63c62787fd8acfd7adafe54a04e4470ace07ef09422fb43e6b9d4a1f37ce651a0007e793fbf4681b4eb30c8e9dc2a01be97497e264b57fd85491e483916c5e
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Wealthsimple
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# AwsCron
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/wealthsimple/aws_cron) [](http://badge.fury.io/rb/aws_cron)
|
4
|
+
|
5
|
+
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
6
|
+
|
7
|
+
# Table of Contents
|
8
|
+
|
9
|
+
- [Features](#features)
|
10
|
+
- [Screencasts](#screencasts)
|
11
|
+
- [Requirements](#requirements)
|
12
|
+
- [Setup](#setup)
|
13
|
+
- [Usage](#usage)
|
14
|
+
- [Tests](#tests)
|
15
|
+
- [Versioning](#versioning)
|
16
|
+
- [Code of Conduct](#code-of-conduct)
|
17
|
+
- [Contributions](#contributions)
|
18
|
+
- [License](#license)
|
19
|
+
- [History](#history)
|
20
|
+
- [Credits](#credits)
|
21
|
+
|
22
|
+
<!-- Tocer[finish]: Auto-generated, don't remove. -->
|
23
|
+
|
24
|
+
# Features
|
25
|
+
|
26
|
+
# Screencasts
|
27
|
+
|
28
|
+
# Requirements
|
29
|
+
|
30
|
+
0. [Ruby 2.3.1](https://www.ruby-lang.org)
|
31
|
+
|
32
|
+
# Setup
|
33
|
+
|
34
|
+
For a secure install, type the following (recommended):
|
35
|
+
|
36
|
+
gem cert --add <(curl --location --silent /gem-public.pem)
|
37
|
+
gem install aws_cron --trust-policy MediumSecurity
|
38
|
+
|
39
|
+
NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification
|
40
|
+
while allowing the installation of unsigned dependencies since they are beyond the scope of this
|
41
|
+
gem.
|
42
|
+
|
43
|
+
For an insecure install, type the following (not recommended):
|
44
|
+
|
45
|
+
gem install aws_cron
|
46
|
+
|
47
|
+
Add the following to your Gemfile:
|
48
|
+
|
49
|
+
gem "aws_cron"
|
50
|
+
|
51
|
+
# Usage
|
52
|
+
|
53
|
+
# Tests
|
54
|
+
|
55
|
+
To test, run:
|
56
|
+
|
57
|
+
bundle exec rake
|
58
|
+
|
59
|
+
# Versioning
|
60
|
+
|
61
|
+
Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
|
62
|
+
|
63
|
+
- Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
|
64
|
+
- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
|
65
|
+
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
66
|
+
|
67
|
+
# Code of Conduct
|
68
|
+
|
69
|
+
Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By
|
70
|
+
participating in this project you agree to abide by its terms.
|
71
|
+
|
72
|
+
# Contributions
|
73
|
+
|
74
|
+
Read [CONTRIBUTING](CONTRIBUTING.md) for details.
|
75
|
+
|
76
|
+
# License
|
77
|
+
|
78
|
+
Copyright (c) 2016 []().
|
79
|
+
Read [LICENSE](LICENSE.md) for details.
|
80
|
+
|
81
|
+
# History
|
82
|
+
|
83
|
+
Read [CHANGES](CHANGES.md) for details.
|
84
|
+
Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
|
85
|
+
|
86
|
+
# Credits
|
87
|
+
|
88
|
+
Developed by [Marco Costa]() at
|
89
|
+
[]().
|
data/lib/aws_cron.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module AwsCron
|
2
|
+
class << self
|
3
|
+
attr_writer :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.reset_configuration!
|
15
|
+
@configuration = Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
ATTRIBUTES = [:logger, :exception_handler]
|
20
|
+
attr_accessor *ATTRIBUTES
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@logger ||= Logger.new(STDOUT)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
# Controller helper concern
|
6
|
+
module AwsCron
|
7
|
+
module Controller
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
# Runs block and ensures error logging and proper JSON return
|
11
|
+
def run(&block)
|
12
|
+
yield
|
13
|
+
rescue => exception
|
14
|
+
AwsCron::log(:error, exception)
|
15
|
+
ensure
|
16
|
+
self.return_object
|
17
|
+
end
|
18
|
+
|
19
|
+
# Runs block using defined timezone for cron scheduling
|
20
|
+
# and ensures error logging and proper JSON return
|
21
|
+
#
|
22
|
+
# For tasks that call this method, make sure to have
|
23
|
+
# cron.yaml call this task in way that allows it to
|
24
|
+
# check programmatically if it needs to be triggered
|
25
|
+
def run_in_tz(cron_str, &block)
|
26
|
+
run do
|
27
|
+
CronRunner.new(cron_str, time_provider).run do
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def return_object
|
36
|
+
raise SecurityError('You must implement return_object with a 200 HTTP response using your preferred web framework')
|
37
|
+
end
|
38
|
+
|
39
|
+
def time_provider
|
40
|
+
Time
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsCron
|
4
|
+
# Gem identity information.
|
5
|
+
module Identity
|
6
|
+
def self.name
|
7
|
+
"aws_cron"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.label
|
11
|
+
"AwsCron"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.version
|
15
|
+
"0.1.1"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.version_label
|
19
|
+
"#{label} #{version}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'parse-cron'
|
2
|
+
|
3
|
+
module AwsCron
|
4
|
+
|
5
|
+
# Cron runner that runs a schedule based on provided time_provider
|
6
|
+
# You should avoid using this class directly
|
7
|
+
class CronRunner
|
8
|
+
def initialize(cron_str, time_provider=Time, leniency_secs=30*60)
|
9
|
+
@cron = ::CronParser.new(cron_str, time_provider)
|
10
|
+
@time_provider = time_provider
|
11
|
+
@leniency_secs = leniency_secs
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(time=@time_provider.now, &block)
|
15
|
+
if should_run(time)
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def should_run(time)
|
21
|
+
last_execution_time = @cron.last(time)
|
22
|
+
|
23
|
+
time >= last_execution_time - @leniency_secs && time < last_execution_time + @leniency_secs
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/tasks/reek.rake
ADDED
metadata
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_cron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Costa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parse-cron
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gemsmith
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '8.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '8.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-state
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.5'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.5'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.7'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.7'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: reek
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.5'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '4.5'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.45'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.45'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- marco@marcotc.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files:
|
173
|
+
- README.md
|
174
|
+
- LICENSE.md
|
175
|
+
files:
|
176
|
+
- LICENSE.md
|
177
|
+
- README.md
|
178
|
+
- lib/aws_cron.rb
|
179
|
+
- lib/aws_cron/configuration.rb
|
180
|
+
- lib/aws_cron/controller.rb
|
181
|
+
- lib/aws_cron/exception_handler.rb
|
182
|
+
- lib/aws_cron/identity.rb
|
183
|
+
- lib/aws_cron/logger.rb
|
184
|
+
- lib/aws_cron/runner.rb
|
185
|
+
- lib/tasks/reek.rake
|
186
|
+
- lib/tasks/rspec.rake
|
187
|
+
- lib/tasks/rubocop.rake
|
188
|
+
homepage: https://github.com/wealthsimple/aws_cron
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata: {}
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 2.5.1
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: AWS Elastic Beanstalk cron scheduling support
|
212
|
+
test_files: []
|