sidekiq-cron-tasks 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0bebc8a18c90f14c7f7b6d2ace03c96daf76ca0
4
+ data.tar.gz: 10adc1c729afd1dd1a8fbd1f2b1b4a6586b73b81
5
+ SHA512:
6
+ metadata.gz: 416113bdf08a72f514a807ea5c6ad8701d08484bf707e93da1cdb4b9e8c46c467c0ed1d76809b7133c53209ef79b817bd479aeb212007833b20b6be309c17345
7
+ data.tar.gz: 9438ab02e0ad0135aa0f74f90868c45112322effda90d5905524cf83bc31897f8c651c5787e5f71b253af674e0dfd7cd1cd8dcac91df735a27b299b5a150c63b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Bernardo Farah
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Sidekiq::Cron::Tasks
2
+
3
+ Adds `rake` and `cap` tasks for loading `Sidekiq::Cron::Job`s from a config
4
+ file.
5
+
6
+ ## Usage
7
+
8
+ #### Rake task
9
+
10
+ You can run the rake task via:
11
+
12
+ ```sh
13
+ bundle exec rake sidekiq_cron:load
14
+ ```
15
+
16
+ It expects a configuration file at `config/sidekiq_cron.yml` in this format:
17
+
18
+ ```yml
19
+ default: &defaults
20
+ rake task does stuff:
21
+ cron: "42 0 * * *"
22
+ class: "RakeTaskJob"
23
+ args:
24
+ - does:stuff
25
+
26
+ development:
27
+ <<: *defaults
28
+
29
+ staging:
30
+ <<: *defaults
31
+
32
+ production:
33
+ <<: *defaults
34
+ ```
35
+
36
+ You can configure the location of this file, as well as name prefixes for tasks:
37
+
38
+ ```rb
39
+ Sidekiq::Cron::Tasks.configure do |config|
40
+ config.file = "/custom/file/path"
41
+ config.prefix = "notmyprefix"
42
+ end
43
+ ```
44
+
45
+ #### Capistrano
46
+
47
+ You can enable this task for Capistrano deployment. It runs around the same time
48
+ that Rails' db migrations do. To enable it:
49
+
50
+ ```rb
51
+ # Capfile
52
+ require 'capistrano/sidekiq-cron'
53
+ ```
54
+
55
+ ## Installation
56
+ Add this line to your application's Gemfile:
57
+
58
+ ```ruby
59
+ gem 'sidekiq-cron-tasks'
60
+ ```
61
+
62
+ And then execute:
63
+ ```bash
64
+ $ bundle
65
+ ```
66
+
67
+ Or install it yourself as:
68
+ ```bash
69
+ $ gem install sidekiq-cron-tasks
70
+ ```
71
+
72
+ ## Contributing
73
+ Contribution directions go here.
74
+
75
+ ## License
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Sidekiq::Cron::Tasks'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,2 @@
1
+ require "capistrano/rails"
2
+ load File.expand_path("../tasks/sidekiq_cron.rake", __FILE__)
@@ -0,0 +1 @@
1
+ require_relative "sidekiq-cron"
@@ -0,0 +1,20 @@
1
+ namespace :deploy do
2
+ desc "Updates Sidekiq::Cron jobs from configuration file"
3
+ task sidekiq_cron: [:set_rails_env] do
4
+ on fetch(:sidekiq_cron_servers) do
5
+ within release_path do
6
+ with rails_env: fetch(:rails_env) do
7
+ execute :rake, "sidekiq_cron:load"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ after "deploy:updated", "deploy:sidekiq_cron"
13
+ end
14
+
15
+ namespace :load do
16
+ task :defaults do
17
+ set :sidekiq_cron_role, fetch(:sidekiq_cron_role, :app)
18
+ set :sidekiq_cron_servers, -> { primary(fetch(:sidekiq_cron_role)) }
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Sidekiq
2
+ module Cron
3
+ module Tasks
4
+ class Configuration
5
+ attr_accessor :file, :prefix
6
+
7
+ def initialize
8
+ @file = ::Rails.root.join("config", "sidekiq_cron.yml")
9
+ @prefix = "sidekiq_cron"
10
+ end
11
+
12
+ def file
13
+ @file || @default_file.call
14
+ end
15
+
16
+ def schedule
17
+ @schedule ||= File.exist?(file) ? YAML.load_file(file).fetch(::Rails.env, {}) : {}
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Sidekiq
2
+ module Cron
3
+ module Tasks
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ load "tasks/sidekiq_cron/load.rake"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Sidekiq
2
+ module Cron
3
+ module Tasks
4
+ VERSION = '0.2.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require "sidekiq-cron"
2
+ require "sidekiq/cron/tasks/railtie"
3
+ require "sidekiq/cron/tasks/configuration"
4
+
5
+ module Sidekiq
6
+ module Cron
7
+ module Tasks
8
+ def self.config
9
+ @config ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield config
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require "sidekiq/cron/tasks"
@@ -0,0 +1 @@
1
+ require_relative "sidekiq-cron-tasks"
@@ -0,0 +1,16 @@
1
+ namespace :sidekiq_cron do
2
+ desc "Load Sidekiq Cron entries from file"
3
+ task load: :environment do
4
+ config = Sidekiq::Cron::Tasks.config
5
+
6
+ next if config.schedule.empty?
7
+
8
+ prefixed_hash = config.schedule.each_with_object({}) do |(name, options), new_hash|
9
+ prefixed_name = name.sub(/\A(#{config.prefix} )?/, config.prefix + " ")
10
+ new_hash[prefixed_name] = options
11
+ end
12
+
13
+ Sidekiq::Cron::Job.all.select { |job| job.name =~ /\A#{config.prefix} / }.each(&:destroy)
14
+ Sidekiq::Cron::Job.load_from_hash prefixed_hash
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-cron-tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bernardo Farah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: capistrano-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sidekiq-cron
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.7'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0.4'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.7'
67
+ - !ruby/object:Gem::Dependency
68
+ name: capistrano
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.4'
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '4.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '4.0'
87
+ description: Adds tasks for Sidekiq Cron loading
88
+ email:
89
+ - ber@bernardo.me
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - MIT-LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - lib/capistrano/sidekiq-cron.rb
98
+ - lib/capistrano/sidekiq_cron.rb
99
+ - lib/capistrano/tasks/sidekiq_cron.rake
100
+ - lib/sidekiq-cron-tasks.rb
101
+ - lib/sidekiq/cron/tasks.rb
102
+ - lib/sidekiq/cron/tasks/configuration.rb
103
+ - lib/sidekiq/cron/tasks/railtie.rb
104
+ - lib/sidekiq/cron/tasks/version.rb
105
+ - lib/sidekiq_cron_tasks.rb
106
+ - lib/tasks/sidekiq_cron/load.rake
107
+ homepage: https://github.com/coverhound/sidekiq-cron-tasks
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Adds tasks for Sidekiq Cron loading
131
+ test_files: []