kiq_tock 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
+ SHA256:
3
+ metadata.gz: 42c1c10ee7b03f00866b54fd451c9926d6ae74c88ac763005770c45ce7e12423
4
+ data.tar.gz: 04a8d06ad92cd33f732727f5580f209d6ad39dda53ef0a22463e36b44edbb757
5
+ SHA512:
6
+ metadata.gz: bf2512976914c61ba93f19a1f9891321c9215c4587e2d05d4c35f8028599f7cd8900bcab35821426d8e5b5818966dad3344991fcb54853049ff38e3c212a164f
7
+ data.tar.gz: b03ca0f0fd0c89ea4ab3a868ef9bf13820371213ae5e65511deb29afea6d41ca4c98e75e5f5074cdaf0170af127d54b8b0961aa4086baa117acaea2c0661879a
@@ -0,0 +1,53 @@
1
+ name: KiqTock gem Github action
2
+
3
+ env:
4
+ DATABASE_URL: postgres://postgres:@localhost:5432/test
5
+ PGPASSWORD: postgres
6
+ PGUSER: postgres
7
+ RAILS_ENV: test
8
+ RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
9
+ REDIS_URL: redis://localhost:6379/0
10
+
11
+ on:
12
+ push:
13
+ branches: '*'
14
+ pull_request:
15
+ branches: [main]
16
+
17
+ jobs:
18
+ build:
19
+ runs-on: ubuntu-latest
20
+
21
+ services:
22
+ db:
23
+ env:
24
+ POSTGRES_USER: postgres
25
+ POSTGRES_PASSWORD: postgres
26
+ image: postgres:latest
27
+ options: >-
28
+ --health-cmd pg_isready
29
+ --health-interval 10s
30
+ --health-timeout 5s
31
+ --health-retries 5
32
+ ports: ["5432:5432"]
33
+
34
+ redis:
35
+ image: redis:latest
36
+ ports: ["6379:6379"]
37
+ options: --entrypoint redis-server
38
+
39
+ steps:
40
+ - uses: actions/checkout@v2
41
+
42
+ - name: Set up Ruby 3
43
+ uses: ruby/setup-ruby@v1
44
+ with:
45
+ ruby-version: '3.0.2'
46
+ bundler-cache: true
47
+
48
+ - name: Run Bundler
49
+ run: bundle install
50
+
51
+ - name: Build and test with minitest and rspec
52
+ run: |
53
+ bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .byebug_history
2
+ .rspec_status
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,47 @@
1
+ require:
2
+ - rubocop-ordered_methods
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.0
8
+
9
+ Layout/HashAlignment:
10
+ EnforcedColonStyle: table
11
+ EnforcedHashRocketStyle: table
12
+
13
+ Layout/LineLength:
14
+ Max: 100
15
+
16
+ Layout/MultilineArrayLineBreaks:
17
+ Enabled: true
18
+
19
+ Layout/MultilineAssignmentLayout:
20
+ Enabled: true
21
+
22
+ Layout/MultilineHashKeyLineBreaks:
23
+ Enabled: true
24
+
25
+ Layout/MultilineMethodArgumentLineBreaks:
26
+ Enabled: true
27
+
28
+ Layout/TrailingWhitespace:
29
+ AllowInHeredoc: false
30
+ Enabled: true
31
+
32
+ RSpec/ExampleLength:
33
+ Max: 10
34
+
35
+ RSpec/MultipleExpectations:
36
+ Enabled: false
37
+
38
+ Style/Documentation:
39
+ Enabled: false
40
+
41
+ Style/StringLiterals:
42
+ Enabled: true
43
+ EnforcedStyle: single_quotes
44
+
45
+ Style/StringLiteralsInInterpolation:
46
+ Enabled: true
47
+ EnforcedStyle: double_quotes
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ kiq_tock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-07-18
4
+
5
+ - Initial release
@@ -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 martin.streicher@gadget.consulting. 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/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in kiq_tock.gemspec
6
+ gemspec
7
+
8
+ gem 'brakeman'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+ gem 'rubocop-ordered_methods'
13
+ gem 'rubocop-rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kiq_tock (0.1.0)
5
+ zeitwerk
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ brakeman (5.1.1)
12
+ byebug (11.1.3)
13
+ diff-lcs (1.4.4)
14
+ parallel (1.20.1)
15
+ parser (3.0.2.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.0.0)
18
+ rake (13.0.6)
19
+ regexp_parser (2.1.1)
20
+ rexml (3.2.5)
21
+ rspec (3.10.0)
22
+ rspec-core (~> 3.10.0)
23
+ rspec-expectations (~> 3.10.0)
24
+ rspec-mocks (~> 3.10.0)
25
+ rspec-core (3.10.1)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-expectations (3.10.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-mocks (3.10.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-support (3.10.2)
34
+ rubocop (1.18.4)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.0.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml
40
+ rubocop-ast (>= 1.8.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.9.0)
44
+ parser (>= 3.0.1.1)
45
+ rubocop-ordered_methods (0.9)
46
+ rubocop (>= 1.0)
47
+ rubocop-rspec (2.4.0)
48
+ rubocop (~> 1.0)
49
+ rubocop-ast (>= 1.1.0)
50
+ ruby-progressbar (1.11.0)
51
+ unicode-display_width (2.0.0)
52
+ zeitwerk (2.4.2)
53
+
54
+ PLATFORMS
55
+ x86_64-darwin-20
56
+ x86_64-linux
57
+
58
+ DEPENDENCIES
59
+ brakeman
60
+ byebug
61
+ kiq_tock!
62
+ rake
63
+ rspec
64
+ rubocop
65
+ rubocop-ordered_methods
66
+ rubocop-rspec
67
+
68
+ BUNDLED WITH
69
+ 2.2.25
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Martin Streicher
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,45 @@
1
+ [![Ruby](https://github.com/gadgetonline/kiq_tock/actions/workflows/main.yml/badge.svg)](https://github.com/gadgetonline/kiq_tock/actions/workflows/main.yml)
2
+
3
+ # KiqTock
4
+
5
+ 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/kiq_tock`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'kiq_tock'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install kiq_tock
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kiq_tock. 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]/kiq_tock/blob/main/CODE_OF_CONDUCT.md).
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the KiqTock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kiq_tock/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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 'kiq_tock'
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/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
data/kiq_tock.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/kiq_tock/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.add_development_dependency 'brakeman', '~> 5.1'
7
+ spec.add_development_dependency 'byebug', '~> 11.1'
8
+ spec.add_development_dependency 'rubocop', '~> 1.18'
9
+ spec.add_development_dependency 'rubocop-ordered_methods', '~> 0.9'
10
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
11
+ spec.add_dependency 'zeitwerk'
12
+
13
+ spec.authors = ['Martin Streicher']
14
+ spec.bindir = 'exe'
15
+ spec.email = ['martin.streicher@gadget.consulting']
16
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
17
+
18
+ spec.files =
19
+ Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
21
+ end
22
+
23
+ spec.homepage = 'https://github.com/gadgetonline/kiq_tock'
24
+ spec.license = 'MIT'
25
+
26
+ spec.metadata['homepage_uri'] = spec.homepage
27
+ spec.metadata['source_code_uri'] = 'https://github.com/gadgetonline/kiq_tock'
28
+ spec.metadata['changelog_uri'] = 'https://github.com/gadgetonline/kiq_tock/CHANGELOG.md.'
29
+
30
+ spec.name = 'kiq_tock'
31
+ spec.require_paths = ['lib']
32
+ spec.required_ruby_version = '>= 3.0.0'
33
+ spec.summary = 'Define peridic jobs in readable text and YAML'
34
+ spec.version = KiqTock::VERSION
35
+ end
data/lib/kiq_tock.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'kiq_tock/version'
4
+ require 'zeitwerk'
5
+
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.setup
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ class Error
5
+ class InvalidDayError < StandardError; end
6
+
7
+ class InvalidHourError < StandardError; end
8
+
9
+ class InvalidMinuteError < StandardError; end
10
+
11
+ class InvalidMonthError < StandardError; end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ class Parser
5
+ DAY_OF_WEEK_SUBSTITUTIONS =
6
+ {
7
+ '0' => %w[sun sunday],
8
+ '1' => %w[mon monday],
9
+ '2' => %w[tue tues tuesday],
10
+ '3' => %w[wed wednesday],
11
+ '4' => %w[thu thur thursday],
12
+ '5' => %w[fri friday],
13
+ '6' => %w[sat saturday]
14
+ }.freeze
15
+
16
+ MONTH_OF_YEAR_SUBSTITUTIONS =
17
+ {
18
+ '0' => %w[jan january],
19
+ '1' => %w[feb february],
20
+ '2' => %w[mar march],
21
+ '3' => %w[apr april],
22
+ '4' => %w[may],
23
+ '5' => %w[jun june],
24
+ '6' => %w[jul july],
25
+ '7' => %w[aug august],
26
+ '8' => %w[sep sept september],
27
+ '9' => %w[oct october],
28
+ '10' => %w[nov november],
29
+ '11' => %w[dec december]
30
+ }.freeze
31
+
32
+ def self.parse(field, cron_expression)
33
+ expression = cron_expression.to_s.gsub(/\s+/, '')
34
+
35
+ case field.to_sym
36
+ when :days_of_week
37
+ translate_days expression
38
+ when :months_of_year
39
+ translate_months expression
40
+ else
41
+ expression
42
+ end.split(/,\s*/)
43
+ end
44
+
45
+ def self.translate(substitutions, cron_expression)
46
+ substitutions.each_pair.inject(cron_expression) do |result, (number, names)|
47
+ names.sort_by(&:length).reverse.inject(result) do |string, name|
48
+ string.gsub(name, number)
49
+ end
50
+ end
51
+ end
52
+
53
+ #
54
+ # Substitute names for numbers, searching for longest matches first
55
+ def self.translate_days(cron_expression)
56
+ translate DAY_OF_WEEK_SUBSTITUTIONS, cron_expression
57
+ end
58
+
59
+ #
60
+ # Substitute names for numbers, searching for longest matches first
61
+ def self.translate_months(cron_expression)
62
+ translate MONTH_OF_YEAR_SUBSTITUTIONS, cron_expression
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module KiqTock
6
+ class Scheduler
7
+ ANY = '*'
8
+ CRON_FIELDS = %i[minutes hours days_of_month days_of_week months_of_year].freeze
9
+ DEFAULT_JOBS_FILE = File.expand_path 'sidekiq/periodic_jobs.yml'
10
+
11
+ def initialize(scheduler:, jobs_file: nil)
12
+ @jobs_file = jobs_file
13
+ @scheduler = scheduler
14
+ end
15
+
16
+ def register_jobs
17
+ jobs.each do |job|
18
+ scheduler.register(
19
+ job[:schedule],
20
+ job[:class_name],
21
+ retries: job[:retry_count]
22
+ )
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def determine_schedule(schedule)
29
+ schedule = schedule_from_hash(schedule) if schedule.is_a?(Hash)
30
+ return schedule if schedule.split.size == CRON_FIELDS.size
31
+
32
+ raise SyntaxError, 'invalid cron schedule string'
33
+ end
34
+
35
+ def interpret(field, value)
36
+ return ANY if (value || '').to_s.size.zero?
37
+
38
+ KiqTock::Parser.parse(field, value).join(',')
39
+ end
40
+
41
+ def jobs
42
+ jobs_yaml.values.compact.map do |job|
43
+ {
44
+ class_name: job[:job],
45
+ retry_count: (job[:retries] || 0).to_i,
46
+ schedule: determine_schedule(job[:schedule] || {})
47
+ }
48
+ end
49
+ end
50
+
51
+ def jobs_yaml
52
+ return Rails.application.config_for(:periodic_jobs) if defined?(Rails)
53
+
54
+ yaml = File.read(jobs_file || DEFAULT_JOBS_FILE)
55
+ YAML.safe_load yaml, aliases: true, filename: jobs_file, symbolize_names: true
56
+ end
57
+
58
+ def schedule_from_hash(hash)
59
+ hash
60
+ .transform_keys(&:to_sym)
61
+ .slice(*CRON_FIELDS)
62
+ .map { |field, value| interpret(field, value) }
63
+ .join(' ')
64
+ end
65
+
66
+ attr_reader :jobs_file, :scheduler
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class BaseValidator
6
+ def self.valid?(value)
7
+ new(value).valid?
8
+ end
9
+
10
+ def initialize(value)
11
+ @value = value
12
+ end
13
+
14
+ def valid?
15
+ raise UnimplementedError, "#{self.class.name} does not implement `valid?`"
16
+ end
17
+
18
+ private
19
+
20
+ def raise_error
21
+ klass = self.class.name.split('::').last.gsub('Validator', '')
22
+ exception_klass = "KiqTock::Error::Invalid#{klass}Error"
23
+
24
+ exception_klass =
25
+ if Object.const_defined?(exception_klass)
26
+ Module.const_get(exception_klass)
27
+ else
28
+ KiqTock::Error
29
+ end
30
+
31
+ raise exception_klass, "'#{value}' is not a valid #{klass.downcase}"
32
+ end
33
+
34
+ attr_reader :value
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class DayValidator < IntegerValidator
6
+ MINIMUM = 0
7
+ MAXIMUM = 6
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class HourValidator < IntegerValidator
6
+ MINIMUM = 0
7
+ MAXIMUM = 23
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class InclusionValidator
6
+ VALID_VALUES = [].freeze
7
+
8
+ def self.valid?(_value)
9
+ self::VALID_VALUES.empty? || self::VALID_VALUES.include?(value)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class IntegerValidator < BaseValidator
6
+ MINIMUM = -Float::INFINITY
7
+ MAXIMUM = Float::INFINITY
8
+
9
+ def valid?
10
+ value.to_s.match?(/\A[+-]?((0)|([1-9]\d*))\z/) || raise_error
11
+
12
+ (self.class::MINIMUM..self.class::MAXIMUM).include?(value)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class MinuteValidator < IntegerValidator
6
+ MINIMUM = 0
7
+ MAXIMUM = 59
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ module Validators
5
+ class MonthValidator < IntegerValidator
6
+ MINIMUM = 0
7
+ MAXIMUM = 11
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiqTock
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiq_tock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Streicher
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: brakeman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.18'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-ordered_methods
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: zeitwerk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - martin.streicher@gadget.consulting
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/workflows/main.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".ruby-gemset"
109
+ - ".ruby-version"
110
+ - CHANGELOG.md
111
+ - CODE_OF_CONDUCT.md
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/setup
119
+ - kiq_tock.gemspec
120
+ - lib/kiq_tock.rb
121
+ - lib/kiq_tock/error.rb
122
+ - lib/kiq_tock/parser.rb
123
+ - lib/kiq_tock/scheduler.rb
124
+ - lib/kiq_tock/validators/base_validator.rb
125
+ - lib/kiq_tock/validators/day_validator.rb
126
+ - lib/kiq_tock/validators/hour_validator.rb
127
+ - lib/kiq_tock/validators/inclusion_validator.rb
128
+ - lib/kiq_tock/validators/integer_validator.rb
129
+ - lib/kiq_tock/validators/minute_validator.rb
130
+ - lib/kiq_tock/validators/month_validator.rb
131
+ - lib/kiq_tock/version.rb
132
+ homepage: https://github.com/gadgetonline/kiq_tock
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ homepage_uri: https://github.com/gadgetonline/kiq_tock
137
+ source_code_uri: https://github.com/gadgetonline/kiq_tock
138
+ changelog_uri: https://github.com/gadgetonline/kiq_tock/CHANGELOG.md.
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 3.0.0
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubygems_version: 3.2.22
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Define peridic jobs in readable text and YAML
158
+ test_files: []