-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ca1e15d
Showing
19 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Run lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
rubocop: | ||
name: "Run lint" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.7 | ||
- name: Lint Ruby code with RuboCop | ||
run: | | ||
gem install bundler | ||
bundle install --jobs 4 --retry 3 | ||
bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
rspec: | ||
name: "Run tests" | ||
if: "!contains(github.event.head_commit.message, '[ci skip]')" | ||
runs-on: ubuntu-latest | ||
env: | ||
BUNDLE_JOBS: 4 | ||
BUNDLE_RETRY: 3 | ||
CI: true | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- ruby: 3.0 | ||
- ruby: 2.7 | ||
- ruby: 2.6 | ||
- ruby: 2.5 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: /home/runner/bundle | ||
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} | ||
restore-keys: | | ||
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} | ||
bundle-${{ matrix.ruby }}- | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
- name: Bundle install | ||
run: | | ||
bundle config path /home/runner/bundle | ||
bundle install | ||
bundle update | ||
- name: Run RSpec | ||
run: | | ||
bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
|
||
Gemfile.lock | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require: | ||
- rubocop-md | ||
- standard/cop/block_single_line_braces | ||
|
||
inherit_gem: | ||
standard: config/base.yml | ||
|
||
AllCops: | ||
Exclude: | ||
- 'bin/*' | ||
- 'tmp/**/*' | ||
- 'Gemfile' | ||
- 'vendor/**/*' | ||
- '.github/**/*' | ||
DisplayCopNames: true | ||
SuggestExtensions: false | ||
TargetRubyVersion: 2.7 | ||
|
||
Standard/BlockSingleLineBraces: | ||
Enabled: false | ||
|
||
Style/FrozenStringLiteralComment: | ||
Enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
- Initial release of yabeda-schked gem. [@skryukov] | ||
|
||
[@skryukov]: https://github.com/skryukov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in yabeda-schked.gemspec | ||
gemspec | ||
|
||
group :development, :test do | ||
gem "pry" | ||
gem "pry-inline" | ||
gem "pry-byebug", platform: :mri | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2021 Svyatoslav Kryukov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[![Gem Version](https://badge.fury.io/rb/yabeda-schked.svg)](https://badge.fury.io/rb/yabeda-schked) | ||
[![Build Status](https://github.com/yabeda-rb/yabeda-schked/actions/workflows/test.yml/badge.svg)](https://github.com/yabeda-rb/yabeda-schked/actions?query=branch%3Amaster) | ||
|
||
# Yabeda::[Schked] | ||
|
||
Built-in metrics for monitoring [Schked] recurring jobs out of the box! Part of the [yabeda] suite. | ||
|
||
<a href="https://evilmartians.com/?utm_source=yabeda-schked&utm_campaign=project_page"> | ||
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"> | ||
</a> | ||
|
||
## Installation | ||
|
||
```ruby | ||
gem "yabeda-schked" | ||
|
||
# Then add monitoring system adapter, e.g.: | ||
# gem "yabeda-prometheus" | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
**And that is it!** Schked metrics are being collected! | ||
|
||
## Metrics | ||
|
||
- Total number of executed jobs: `schked_jobs_executed_total` - (the jobs' `name`s and whether their execution was `success`ful) | ||
- Time of job run: `schked_job_execution_runtime` (seconds per job execution, segmented by the jobs' `name`s, and whether their execution was `success`ful) | ||
|
||
❗ Notice: Schked jobs without a name specified (with `as` or `name` attribute) will be marked with the name `'none'`, so it's highly recommended to specify unique names for all jobs. | ||
|
||
## Development | ||
|
||
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. | ||
|
||
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). | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-schked. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). | ||
|
||
|
||
|
||
[Schked]: https://github.com/bibendi/schked "Framework agnostic Rufus-scheduler wrapper to run recurring jobs" | ||
[yabeda]: https://github.com/yabeda-rb/yabeda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
require "rubocop/rake_task" | ||
|
||
RuboCop::RakeTask.new | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: %i[rubocop spec] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "yabeda/schked" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require "schked" | ||
require "yabeda" | ||
|
||
require_relative "schked/version" | ||
|
||
module Yabeda | ||
module Schked | ||
class Error < StandardError; end | ||
|
||
LONG_RUNNING_JOB_RUNTIME_BUCKETS = [ | ||
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus) | ||
30, 60, 120, 300, 1800, 3600, 21_600 # Schked jobs may be very long-running | ||
].freeze | ||
|
||
def self.job_name(job) | ||
name = job.name || job.opts[:as] | ||
return name if name | ||
|
||
warn "❗Warning: No name specified for the job #{job.id}, using `'none'` as default." | ||
"none" | ||
end | ||
|
||
Yabeda.configure do | ||
group :schked | ||
|
||
counter :jobs_executed_total, | ||
tags: %i[job success], | ||
comment: "A counter of the number of jobs executed." | ||
|
||
histogram :job_execution_runtime, | ||
comment: "A histogram of the job execution time.", | ||
unit: :seconds, | ||
per: :job, | ||
tags: %i[job success], | ||
buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS | ||
end | ||
|
||
::Schked.config.register_callback(:after_finish) do |job| | ||
labels = {success: !job.opts[:failed], job: job_name(job)} | ||
Yabeda.schked.job_execution_runtime.measure(labels, job.last_work_time.round(3)) | ||
Yabeda.schked.jobs_executed_total.increment(labels) | ||
end | ||
|
||
::Schked.config.register_callback(:on_error) do |job| | ||
job.opts[:failed] = true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Yabeda | ||
module Schked | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "yabeda/schked" | ||
|
||
require_relative "support/schked" | ||
|
||
RSpec.configure do |config| | ||
# Enable flags like --only-failures and --next-failure | ||
config.example_status_persistence_file_path = ".rspec_status" | ||
|
||
# Disable RSpec exposing methods globally on `Module` and `main` | ||
config.disable_monkey_patching! | ||
|
||
config.expect_with :rspec do |c| | ||
c.syntax = :expect | ||
end | ||
|
||
config.before(:all) do | ||
Yabeda.configure! | ||
Schked.config.logger = Logger.new(nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
at "2020-01-01 00:00:00", as: "SuccessfulJob", blocking: true do | ||
:ok | ||
end | ||
|
||
at "2020-01-01 00:00:00", as: "FailedJob", blocking: true do | ||
raise StandardError, "Boom!" | ||
end | ||
|
||
at "2020-01-01 00:00:00", tag: "without_name", blocking: true do | ||
:ok | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
Schked.config.paths << File.expand_path("schedule.rb", __dir__) |
Oops, something went wrong.