timeoutable 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +109 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Dockerfile +16 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/Makefile +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/publish_gemfury +27 -0
- data/bin/publish_git +38 -0
- data/bin/setup +8 -0
- data/bin/version +7 -0
- data/docker-compose.yml +13 -0
- data/lib/timeoutable.rb +67 -0
- data/lib/timeoutable/testable_klass.rb +51 -0
- data/lib/timeoutable/version.rb +12 -0
- data/timeoutable.gemspec +34 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f5260b27d155d50a7d7f7fcbe4da981ce32c8c952d9da1d418108613b524f55
|
4
|
+
data.tar.gz: 617888199e17a4fb1d36c9492233c62bdafa08b4545c19b043afb8434cafe2e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 128cd789fc6cf75a3570f28a08208eb277b6a05f8b02770e0d0b7968a08535b2da2972edf3a56de75e0905448c0476754bd55efb15614a0477a5facf41325c39
|
7
|
+
data.tar.gz: 12dd063051af4a1b5f37e3dd8278232382baa57c7fb886b3160b733f2bc01b93dedc1e4109e5268a62a2f532f7f9ad20fad0f54dbf4d3c6bb67221e6f2b8ba29
|
@@ -0,0 +1,109 @@
|
|
1
|
+
version: 2.1 # Use 2.1 to enable using orbs and other features.
|
2
|
+
|
3
|
+
# Declare the orbs that we'll use in our config.
|
4
|
+
# read more about orbs: https://circleci.com/docs/2.0/using-orbs/
|
5
|
+
orbs:
|
6
|
+
ruby: circleci/ruby@1.0
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build: # our first job, named "build"
|
10
|
+
docker:
|
11
|
+
- image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.
|
12
|
+
steps:
|
13
|
+
- checkout # pull down our git code.
|
14
|
+
- ruby/install-deps # use the ruby orb to install dependencies
|
15
|
+
environment:
|
16
|
+
|
17
|
+
publish-gemfury:
|
18
|
+
docker:
|
19
|
+
- image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
|
20
|
+
environment:
|
21
|
+
BUNDLE_JOBS: "3"
|
22
|
+
BUNDLE_RETRY: "3"
|
23
|
+
RAILS_ENV: test
|
24
|
+
steps:
|
25
|
+
- checkout
|
26
|
+
- ruby/install-deps
|
27
|
+
- run:
|
28
|
+
name: Publish Gemfury
|
29
|
+
command: |
|
30
|
+
bin/publish_gemfury
|
31
|
+
publish-github:
|
32
|
+
docker:
|
33
|
+
- image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
|
34
|
+
environment:
|
35
|
+
BUNDLE_JOBS: "3"
|
36
|
+
BUNDLE_RETRY: "3"
|
37
|
+
RAILS_ENV: test
|
38
|
+
steps:
|
39
|
+
- checkout
|
40
|
+
- ruby/install-deps
|
41
|
+
- run:
|
42
|
+
name: 'Get Go'
|
43
|
+
command: |
|
44
|
+
sudo apt-get update -qq
|
45
|
+
sudo apt-get -y --no-install-recommends install golang-go
|
46
|
+
- run:
|
47
|
+
name: 'Set Git stats'
|
48
|
+
command: |
|
49
|
+
git config user.name $GITHUB_USER
|
50
|
+
git config user.email $GITHUB_EMAIL
|
51
|
+
- run:
|
52
|
+
name: 'Download GHR'
|
53
|
+
command: |
|
54
|
+
curl -sSL https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz | tar xz -f - -C . ghr_v0.13.0_linux_amd64/ghr
|
55
|
+
mv ghr_v0.13.0_linux_amd64/ghr .
|
56
|
+
rm -rf ghr_v0.13.0_linux_amd64
|
57
|
+
chmod 0755 ghr
|
58
|
+
- run:
|
59
|
+
name: Publish Git
|
60
|
+
command: |
|
61
|
+
export GHRLOCATION=ghr
|
62
|
+
bin/publish_git
|
63
|
+
test:
|
64
|
+
docker:
|
65
|
+
- image: cimg/ruby:2.7-node
|
66
|
+
- image: circleci/redis:latest
|
67
|
+
environment:
|
68
|
+
BUNDLE_JOBS: "3"
|
69
|
+
BUNDLE_RETRY: "3"
|
70
|
+
RAILS_ENV: test
|
71
|
+
# A series of steps to run, some are similar to those in "build".
|
72
|
+
steps:
|
73
|
+
- checkout
|
74
|
+
- ruby/install-deps
|
75
|
+
- run:
|
76
|
+
name: Setup Climate Control test-reporter
|
77
|
+
command: |
|
78
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
79
|
+
chmod +x ./cc-test-reporter
|
80
|
+
- run:
|
81
|
+
name: Run le tests
|
82
|
+
command: |
|
83
|
+
./cc-test-reporter before-build
|
84
|
+
SIMPLE_COV_RUN=true bundle exec rspec --format RspecJunitFormatter --out test-results/rspec/rspec.xml --format progress --color
|
85
|
+
./cc-test-reporter after-build format-coverage -t simplecov
|
86
|
+
|
87
|
+
workflows:
|
88
|
+
version: 2
|
89
|
+
yeet-le-jobs:
|
90
|
+
jobs:
|
91
|
+
- build
|
92
|
+
- test:
|
93
|
+
requires:
|
94
|
+
- build
|
95
|
+
- publish-github:
|
96
|
+
requires:
|
97
|
+
- test
|
98
|
+
filters:
|
99
|
+
branches:
|
100
|
+
only:
|
101
|
+
- main
|
102
|
+
|
103
|
+
- publish-gemfury:
|
104
|
+
requires:
|
105
|
+
- test
|
106
|
+
filters:
|
107
|
+
branches:
|
108
|
+
only:
|
109
|
+
- main
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mtaylor@chime.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
FROM ruby:3.0.1
|
2
|
+
RUN cd /tmp && curl -L --output ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_amd64.tar.gz && \
|
3
|
+
tar -xzvf ghr.tar.gz && chmod +x ghr_v0.12.0_linux_amd64/ghr && mv ghr_v0.12.0_linux_amd64/ghr /usr/local/bin/ghr && rm -rf /tmp/*
|
4
|
+
|
5
|
+
WORKDIR /gem
|
6
|
+
COPY Gemfile /gem/Gemfile
|
7
|
+
|
8
|
+
COPY timeoutable.gemspec /gem/timeoutable.gemspec
|
9
|
+
COPY lib/timeoutable/version.rb /gem/lib/timeoutable/version.rb
|
10
|
+
|
11
|
+
|
12
|
+
RUN gem update --system && gem install bundler && bundle install --jobs=3 --retry=3 && \
|
13
|
+
rm -rf /usr/local/bundle/cache
|
14
|
+
|
15
|
+
COPY . /gem
|
16
|
+
RUN gem build timeoutable
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
timeoutable (1.0.0)
|
5
|
+
timeout
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
docile (1.4.0)
|
13
|
+
method_source (1.0.0)
|
14
|
+
pry (0.14.1)
|
15
|
+
coderay (~> 1.1)
|
16
|
+
method_source (~> 1.0)
|
17
|
+
rspec (3.10.0)
|
18
|
+
rspec-core (~> 3.10.0)
|
19
|
+
rspec-expectations (~> 3.10.0)
|
20
|
+
rspec-mocks (~> 3.10.0)
|
21
|
+
rspec-core (3.10.1)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-expectations (3.10.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-mocks (3.10.2)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-support (3.10.2)
|
30
|
+
rspec_junit_formatter (0.4.1)
|
31
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
32
|
+
simplecov (0.21.2)
|
33
|
+
docile (~> 1.1)
|
34
|
+
simplecov-html (~> 0.11)
|
35
|
+
simplecov_json_formatter (~> 0.1)
|
36
|
+
simplecov-html (0.12.3)
|
37
|
+
simplecov_json_formatter (0.1.3)
|
38
|
+
timeout (0.1.1)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
x86_64-linux
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
pry
|
45
|
+
rspec (~> 3.0)
|
46
|
+
rspec_junit_formatter
|
47
|
+
simplecov
|
48
|
+
timeoutable!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.2.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Matt Taylor
|
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/Makefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.PHONY: bash build bundle rspec
|
2
|
+
|
3
|
+
APP_NAME?=timeoutable
|
4
|
+
|
5
|
+
build: #: Build the containers that we'll need
|
6
|
+
docker-compose build --pull
|
7
|
+
|
8
|
+
bash: #: Get a bash prompt on the core container
|
9
|
+
docker-compose run --rm -e RAILS_ENV=development $(APP_NAME) bash
|
10
|
+
|
11
|
+
bash_test: #: Get a test bash prompt on the core container
|
12
|
+
docker-compose run --rm -e RAILS_ENV=test $(APP_NAME) bash
|
13
|
+
|
14
|
+
down: #: Bring down the service -- Destroys everything in redis and all containers
|
15
|
+
docker-compose down
|
16
|
+
|
17
|
+
clean: #: Clean up stopped/exited containers
|
18
|
+
docker-compose rm -f
|
19
|
+
|
20
|
+
bundle: #: install gems for Dummy App with
|
21
|
+
docker-compose run --rm $(APP_NAME) bundle install
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Timeoutable
|
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/timeoutable`. 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 'timeoutable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install timeoutable
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/timeoutable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/timeoutable/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Timeoutable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/timeoutable/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "timeoutable"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/publish_gemfury
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
if [ -z "$GEMFURY_TOKEN" ]; then
|
4
|
+
echo 'Environment variable GEMFURY_TOKEN is not present'
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
VERSION=$(bin/version)
|
9
|
+
PACKAGE=timeoutable-${VERSION}.gem
|
10
|
+
|
11
|
+
# if [ $(git tag -l "$VERSION") ]; then
|
12
|
+
# echo "Pre existing version $VERSION, not tagging."
|
13
|
+
# echo "Pre existing version $VERSION, not pushing to gemfury."
|
14
|
+
# exit 0
|
15
|
+
# fi
|
16
|
+
|
17
|
+
# Build and publish to Gemfury
|
18
|
+
gem build timeoutable.gemspec
|
19
|
+
FILE=$(pwd)/${PACKAGE}
|
20
|
+
echo "Finished building $FILE"
|
21
|
+
|
22
|
+
# push to gemfury
|
23
|
+
curl --fail -F package=@${FILE} https://${GEMFURY_TOKEN}@push.fury.io/${GEMFURY_USER}/
|
24
|
+
echo "Finished Pushing to Gemfury"
|
25
|
+
|
26
|
+
# start fresh
|
27
|
+
rm timeoutable.gemspec
|
data/bin/publish_git
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
if [ -z "$GITHUB_TOKEN" ]; then
|
4
|
+
echo 'Environment variable GITHUB_TOKEN is not present'
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
if [ -z "$GITHUB_USER" ]; then
|
9
|
+
echo 'Environment variable GITHUB_USER is not present'
|
10
|
+
exit 1
|
11
|
+
fi
|
12
|
+
|
13
|
+
|
14
|
+
VERSION=$(bin/version)
|
15
|
+
PACKAGE=timeoutable-${VERSION}.gem
|
16
|
+
|
17
|
+
# if [ $(git tag -l "$VERSION") ]; then
|
18
|
+
# echo "Pre existing version $VERSION, not tagging."
|
19
|
+
# exit 0
|
20
|
+
# fi
|
21
|
+
|
22
|
+
gem build timeoutable.gemspec
|
23
|
+
FILE=$(pwd)/${PACKAGE}
|
24
|
+
echo "Finished building $FILE"
|
25
|
+
|
26
|
+
# create tag in repo
|
27
|
+
git tag -a $VERSION -m "$VERSION"
|
28
|
+
git push https://${GITHUB_TOKEN}@github.com/${GITHUB_USER}/timeoutable.git $VERSION
|
29
|
+
echo "Finished Tagging to git"
|
30
|
+
|
31
|
+
|
32
|
+
# send artifacts to git
|
33
|
+
SHA=$(git rev-parse HEAD)
|
34
|
+
./$GHRLOCATION -soft -t ${GITHUB_TOKEN} -u ${GITHUB_USER} -r timeoutable -c ${SHA} ${VERSION} *.gem
|
35
|
+
echo "Finished Pushing artificat to Git"
|
36
|
+
|
37
|
+
# start fresh
|
38
|
+
rm timeoutable.gemspec
|
data/bin/setup
ADDED
data/bin/version
ADDED
data/docker-compose.yml
ADDED
data/lib/timeoutable.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'timeoutable/version'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module Timeoutable
|
7
|
+
class TimeoutExceeded < StandardError; end
|
8
|
+
|
9
|
+
PROC = Proc.new do |warn_sec, timeout_sec, proc, exception, message, debug, &block|
|
10
|
+
LOGGER.info "at: PROC; begining" if debug
|
11
|
+
|
12
|
+
sec_to_raise = timeout_sec - warn_sec
|
13
|
+
begin
|
14
|
+
from = debug ? "from #{caller_locations(1, 1)[0]}" : nil
|
15
|
+
x = Thread.current
|
16
|
+
# do everything in a new thread
|
17
|
+
y = Thread.start {
|
18
|
+
LOGGER.info "at: PROC; second thread; about to start" if debug
|
19
|
+
Thread.current.name = from
|
20
|
+
# block for warning in new thread
|
21
|
+
begin
|
22
|
+
LOGGER.info "at: PROC; second thread; starting warn time for #{warn_sec}'s " if debug
|
23
|
+
sleep warn_sec
|
24
|
+
rescue => e
|
25
|
+
x.raise e
|
26
|
+
else
|
27
|
+
# yield back during warning time so downstream can do some prep work
|
28
|
+
LOGGER.info "at: PROC; second thread; trying to warn in main thread" if debug
|
29
|
+
proc.call(x, warn_sec)
|
30
|
+
end
|
31
|
+
|
32
|
+
# block additional seconds to raise for
|
33
|
+
begin
|
34
|
+
LOGGER.info "at: PROC; second thread; starting violent exection time for #{sec_to_raise}'s " if debug
|
35
|
+
sleep sec_to_raise
|
36
|
+
rescue => e
|
37
|
+
LOGGER.info "at: PROC; second thread; Error occured" if debug
|
38
|
+
x.raise e
|
39
|
+
else
|
40
|
+
LOGGER.info "at: PROC; second thread; trying to raise in main thread" if debug
|
41
|
+
x.raise exception, message
|
42
|
+
end
|
43
|
+
}
|
44
|
+
LOGGER.info "at: PROC; second thread; fully spooled" if debug
|
45
|
+
# after thread starts, yield back to calle function with max timout
|
46
|
+
block.call(timeout_sec)
|
47
|
+
ensure
|
48
|
+
if y
|
49
|
+
LOGGER.info "at: PROC; Second thread still exists. Returned in time" if debug
|
50
|
+
y.kill
|
51
|
+
y.join
|
52
|
+
else
|
53
|
+
LOGGER.info "at: PROC; Second thread no longer exists. Failed to return in time" if debug
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
LOGGER = Logger.new($stdout)
|
59
|
+
|
60
|
+
def self.timeout(warn:, timeout:, proc: ->(_, _) {}, exception: TimeoutExceeded, message: nil, debug: false, &block)
|
61
|
+
raise ArgumentError, 'Block not given' unless block_given?
|
62
|
+
|
63
|
+
LOGGER.info "at: timeout; valid bock given" if debug
|
64
|
+
message ||= "Execution exceeded #{timeout} seconds."
|
65
|
+
PROC.call(warn, timeout, proc, exception, message, debug, &block)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Timeoutable
|
6
|
+
class TestableKlass
|
7
|
+
BIT_NAME = 'testable_bit_change'
|
8
|
+
|
9
|
+
# :nocov:
|
10
|
+
def self.perform_test(warn: 2, timeout: 3, sleep_after: 0.1 , sleep_for: 0.1, logger: Logger.new($stdout))
|
11
|
+
params = {
|
12
|
+
warn: warn,
|
13
|
+
timeout: timeout,
|
14
|
+
proc: ->(thread, sec) { thread[BIT_NAME] = 1; logger.warn('at: proc -- Set Bit') },
|
15
|
+
message: "Yoooo. Your code violently blew up. Handle it accordingly",
|
16
|
+
}
|
17
|
+
Timeoutable.timeout(**params) do
|
18
|
+
new.execute(sleep_after: sleep_after, sleep_for: sleep_for)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :logger
|
23
|
+
|
24
|
+
def initialize(logger: Logger.new($stdout))
|
25
|
+
@logger = logger
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute(sleep_after:, sleep_for:, max_iterations: 10_000, raise_warn: false, raise_timeout: false)
|
29
|
+
logger.info("at: execute -- Start")
|
30
|
+
count = 0
|
31
|
+
while count <= max_iterations && Thread.current[BIT_NAME].nil?
|
32
|
+
raise StandardError, 'Throwing error before warn bit' if raise_warn
|
33
|
+
logger.info("at: execute -- sleeping for #{sleep_for}'s [#{count} iterations]")
|
34
|
+
sleep(sleep_for)
|
35
|
+
count += 1
|
36
|
+
end
|
37
|
+
raise StandardError, 'Throwing error after warn bit' if raise_timeout
|
38
|
+
|
39
|
+
logger.info("at: execute -- Worker noticed sleep bit changed -- Cycle broken")
|
40
|
+
|
41
|
+
logger.warn("at: execute -- sleeping 1 last time for #{sleep_after}'s")
|
42
|
+
sleep(sleep_after)
|
43
|
+
logger.warn("at: execute -- returning after sleep")
|
44
|
+
logger.info("at: execute -- End")
|
45
|
+
ensure
|
46
|
+
logger.info("at: execute (ensure) -- ensure bit resetting")
|
47
|
+
end
|
48
|
+
|
49
|
+
# :nocov:
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Timeoutable
|
4
|
+
MAJOR = 1 # With backwards incompatability. Requires annoucment and update documentation
|
5
|
+
MINOR = 0 # With feature launch. Documentation of upgrade is useful via a changelog
|
6
|
+
PATCH = 0 # With minor upgrades or patcing a small bug. No changelog necessary
|
7
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
|
+
|
9
|
+
def self.get_version
|
10
|
+
puts VERSION
|
11
|
+
end
|
12
|
+
end
|
data/timeoutable.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/timeoutable/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "timeoutable"
|
7
|
+
spec.version = Timeoutable::VERSION
|
8
|
+
spec.authors = ["Matt Taylor"]
|
9
|
+
spec.email = ["mattius.taylor@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Extension of Ruby's Timeout::timeout method"
|
12
|
+
spec.description = "Extends Timeout::timeout to add a warning capabilit. Potentially allows for a graceful shutdown"
|
13
|
+
spec.homepage = "https://github.com/matt-taylor/timeoutable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency 'timeout'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timeoutable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Taylor
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: timeout
|
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
|
+
description: Extends Timeout::timeout to add a warning capabilit. Potentially allows
|
28
|
+
for a graceful shutdown
|
29
|
+
email:
|
30
|
+
- mattius.taylor@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".circleci/config.yml"
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rspec"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- CODE_OF_CONDUCT.md
|
40
|
+
- Dockerfile
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE.txt
|
44
|
+
- Makefile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- bin/console
|
48
|
+
- bin/publish_gemfury
|
49
|
+
- bin/publish_git
|
50
|
+
- bin/setup
|
51
|
+
- bin/version
|
52
|
+
- docker-compose.yml
|
53
|
+
- lib/timeoutable.rb
|
54
|
+
- lib/timeoutable/testable_klass.rb
|
55
|
+
- lib/timeoutable/version.rb
|
56
|
+
- timeoutable.gemspec
|
57
|
+
homepage: https://github.com/matt-taylor/timeoutable
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
homepage_uri: https://github.com/matt-taylor/timeoutable
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.4.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.2.20
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Extension of Ruby's Timeout::timeout method
|
81
|
+
test_files: []
|