ruby-clock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba2d9d1626f38c8027978a5528cfd6697e58d754f68c3d12988e2cb4a0bca5ba
4
+ data.tar.gz: 07e9f670929519445fb9133af33bdd16e6a1f4188469c6f62a7c7bd8157ecce4
5
+ SHA512:
6
+ metadata.gz: b684d6ed9b2621e444db1fb9fc66249f31723d972573e7aadde4a38e568c3517dc411b6d07c6c10d4d6bda6580b6cd525870bd157980364d91502bc0601bce2f
7
+ data.tar.gz: fea438780102ed99f7db1bae99af487435fc0b89e6926a131e65b874a7efdc424bc53024386866612e95faa76f51880dee1582adc5277e8d79fc1eb9f7932b79
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+
4
+ # gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ rake (12.3.3)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rake (~> 12.0)
11
+
12
+ BUNDLED WITH
13
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 John Bachir
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.
@@ -0,0 +1,107 @@
1
+ # ruby-clock
2
+
3
+ ruby-clock is a [job scheduler](https://en.wikipedia.org/wiki/Job_scheduler),
4
+ known by heroku as a [clock process](https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes).
5
+ In many cases it can replace the use of cron.
6
+
7
+ This gem is very small with very few lines of code. For all its scheduling capabilities,
8
+ it relies on the venerable [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler/).
9
+ rufus-scheduler
10
+ [does not aim to be a standalone process or a cron replacement](https://github.com/jmettraux/rufus-scheduler/issues/307),
11
+ ruby-clock does.
12
+
13
+ Jobs are all run in their own parallel threads within the same process.
14
+
15
+ The clock process will respond to signals INT (^c at the command line) and
16
+ TERM (signal sent by environments such as Heroku and other PaaS's when shutting down).
17
+ In both cases, the clock will stop running jobs and give existing jobs 29 seconds
18
+ to stop before killing them.
19
+
20
+ ## Installation
21
+
22
+ Add these lines to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'ruby-clock'
26
+
27
+ # ruby-clock currently depends on rufus-scheduler master
28
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
29
+ gem 'rufus-scheduler', github: 'jmettraux/rufus-scheduler'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle install
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install ruby-clock
39
+
40
+ ## Usage
41
+
42
+ Write a file with your scheduled jobs in it, named Clockfile. The DSL and capabilities
43
+ are the same as those of [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler/).
44
+ Read the rufus-scheduler documentation to see what you can do.
45
+
46
+ ```ruby
47
+ schedule.every('5 minutes') do
48
+ UserDataReports.generate
49
+ end
50
+
51
+ # do something every day, five minutes after midnight
52
+ scheduler.cron '5 0 * * *' do
53
+ DailyActivitySummary.generate_and_send
54
+ end
55
+ ```
56
+
57
+ To start your clock process:
58
+
59
+ bundle exec clock
60
+
61
+ ### Rails
62
+
63
+ To run your clock process in your app's environment:
64
+
65
+ bundle exec rails runner clock
66
+
67
+ ### Non-Rails
68
+
69
+ Require your app's code at the top of Clockfile:
70
+
71
+ ```ruby
72
+ require_relative './lib/app.rb'
73
+ schedule.every('5 minutes') do
74
+ ...
75
+ ```
76
+
77
+ ### Heroku and other PaaS's
78
+
79
+ Add this line to your Procfile
80
+
81
+ ```
82
+ clock: bundle exec rails runer clock
83
+ ```
84
+
85
+ ## More Config and Capabilities
86
+
87
+ ### Error Handling
88
+
89
+ todo
90
+
91
+ ### Callbacks
92
+
93
+ todo
94
+
95
+ ### rufus-scheduler Options
96
+
97
+ All rufus-scheduler options are set to defaults. The `schedule` variable
98
+ Available in your Clockfile is and instance of `Rufus::Scheduler`,
99
+ so anything you can do on this instance, you can do in your Clockfile.
100
+
101
+ Perhaps in the future ruby-clock will add some easier specific configuration
102
+ capabilities for some things. Let me know if you have a request!
103
+
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_clock"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ruby-clock'
4
+ include RubyClock
5
+
6
+ listen_to_signals
7
+
8
+ load 'Clockfile'
9
+
10
+ run_jobs
@@ -0,0 +1,23 @@
1
+ require "ruby-clock/version"
2
+ require 'rufus-scheduler'
3
+
4
+ module RubyClock
5
+ def shutdown
6
+ puts "Shutting down 🐈️ 👋"
7
+ puts Rufus::Scheduler.singleton.shutdown(wait: 29)
8
+ exit
9
+ end
10
+
11
+ def listen_to_signals
12
+ Signal.trap('INT') { shutdown }
13
+ Signal.trap('TERM') { shutdown }
14
+ end
15
+
16
+ def schedule
17
+ Rufus::Scheduler.singleton
18
+ end
19
+
20
+ def run_jobs
21
+ Rufus::Scheduler.singleton.join
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module RubyClock
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/ruby-clock/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ruby-clock"
5
+ spec.version = RubyClock::VERSION
6
+ spec.authors = ["John Bachir"]
7
+ spec.email = ["j@jjb.cc"]
8
+
9
+ spec.summary = 'A "clock" process for invoking ruby code within a persistent runtime'
10
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = "https://github.com/jjb/ruby-clock"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/jjb/ruby-clock"
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+
24
+ # todo: make this not depend on git? which wasted a lot of debugging time
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # spec.add_dependency "rufus-scheduler", '~> 3.7.0'
33
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-clock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Bachir
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - j@jjb.cc
16
+ executables:
17
+ - clock
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - exe/clock
30
+ - lib/ruby-clock.rb
31
+ - lib/ruby-clock/version.rb
32
+ - ruby-clock.gemspec
33
+ homepage: https://github.com/jjb/ruby-clock
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/jjb/ruby-clock
38
+ source_code_uri: https://github.com/jjb/ruby-clock
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.1.2
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A "clock" process for invoking ruby code within a persistent runtime
58
+ test_files: []