crossing_guard 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.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +14 -0
- data/README.md +25 -0
- data/Rakefile +3 -0
- data/bin/crossing_guard +13 -0
- data/crossing_guard.gemspec +19 -0
- data/lib/config.rb +39 -0
- data/lib/crossing_guard.rb +25 -0
- data/lib/crossing_guard/version.rb +11 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Crossing Guard
|
2
|
+
|
3
|
+
> A gem for simple, periodic, management of crons and shell calls.
|
4
|
+
|
5
|
+
Crossing Guard is simple way to wait unix commands, usually while other resource-heavy
|
6
|
+
processes are running. Crossing Guard will de-dupe the waiting processes before running the queue.
|
7
|
+
|
8
|
+
**Crossing Guard does not daemonize itself**. If you do not have a regular process
|
9
|
+
that will call Crossing Guard (e.g. to try new jobs), then you must run it 'blank' via cron
|
10
|
+
or other daemon(ization).
|
11
|
+
|
12
|
+
Examples will come in time; for now, see the *tiny* source.
|
13
|
+
|
14
|
+
# Roadmap
|
15
|
+
|
16
|
+
* clearing of queue(s) after a fixed interval. hour, or date.
|
17
|
+
* regex-based wait queues.
|
18
|
+
|
19
|
+
## Related Projects
|
20
|
+
|
21
|
+
* [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler): Cron Inside Ruby
|
22
|
+
* [whenever](https://github.com/javan/whenever): Ruby makes unix crons
|
23
|
+
* [launchd](http://nb.nathanamy.org/2012/07/schedule-jobs-using-launchd/): Record and replay launchd-crons even when in sleep mode
|
24
|
+
* cron: Perennial workhorse of most *nix operating systems.
|
25
|
+
* [daemons](http://daemons.rubyforge.org/): Daemonize any processes
|
data/Rakefile
ADDED
data/bin/crossing_guard
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'crossing_guard'
|
3
|
+
|
4
|
+
if ARGV.any? && (ARGV.first == '--help' || ARGV.first == '-h')
|
5
|
+
puts "usage: $0 <one-liner command>"
|
6
|
+
elsif ARGV.any? && CrossingGuard.config[:state] == 'blue-pill'
|
7
|
+
CrossingGuard.sleep ARGV[0]
|
8
|
+
elsif CrossingGuard.config[:state] == 'red-pill'
|
9
|
+
`#{ARGV[0]}`
|
10
|
+
CrossingGuard.awaken if File.exists?(CrossingGuard.config[:ops])
|
11
|
+
else
|
12
|
+
# warn
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "crossing_guard/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'crossing_guard'
|
7
|
+
s.version = CrossingGuard::Version.to_s
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Zachary StarkJones']
|
10
|
+
s.email = ['zak@newalexandria.org']
|
11
|
+
s.homepage = 'http://github.com/newalexandria/crossing_guard'
|
12
|
+
s.summary = 'An on/off switch for crons and other shell traffic'
|
13
|
+
s.description = 'Configure wait times for crons (or any shell calls) in a central place. Currently supports a single wait queue.'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_path = ['lib']
|
19
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# via nicholasbrochu.com
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Config
|
6
|
+
# Configuration defaults
|
7
|
+
@config = { :ops => "/etc/crossing_guard.ops",
|
8
|
+
:conf => '/etc/crossing_guard.yml',
|
9
|
+
:state => 'red-pill' }
|
10
|
+
|
11
|
+
@valid_config_keys = @config.keys
|
12
|
+
|
13
|
+
# Configure through yaml file
|
14
|
+
def self.using(path_to_yaml_file)
|
15
|
+
begin
|
16
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
17
|
+
rescue Errno::ENOENT
|
18
|
+
puts(:warning, "YAML configuration file couldn't be found. Using defaults."); return
|
19
|
+
# log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
|
20
|
+
rescue Psych::SyntaxError
|
21
|
+
puts(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
|
22
|
+
# log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
|
23
|
+
end
|
24
|
+
|
25
|
+
configure(config)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.config
|
29
|
+
@config
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Configure through hash
|
35
|
+
def self.configure(opts = {})
|
36
|
+
opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'config'
|
2
|
+
Config.using(Config.config[:conf])
|
3
|
+
|
4
|
+
module CrossingGuard
|
5
|
+
def self.config
|
6
|
+
@config ||= Config.config
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.sleep(command)
|
10
|
+
ops_file = File.open(config[:ops], 'a+') do |f|
|
11
|
+
f.write "#{command}\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.awaken
|
16
|
+
filename = config[:ops]
|
17
|
+
file_safe = filename+'.op'
|
18
|
+
|
19
|
+
File.rename(filename, file_safe)
|
20
|
+
IO.readlines(file_safe).uniq.each do |d|
|
21
|
+
`#{d}`
|
22
|
+
end
|
23
|
+
File.delete(file_safe)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crossing_guard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Zachary StarkJones
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-11 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Configure wait times for crons (or any shell calls) in a central place. Currently supports a single wait queue.
|
23
|
+
email:
|
24
|
+
- zak@newalexandria.org
|
25
|
+
executables:
|
26
|
+
- crossing_guard
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Gemfile.lock
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- bin/crossing_guard
|
38
|
+
- crossing_guard.gemspec
|
39
|
+
- lib/config.rb
|
40
|
+
- lib/crossing_guard.rb
|
41
|
+
- lib/crossing_guard/version.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/newalexandria/crossing_guard
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- - lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.6.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: An on/off switch for crons and other shell traffic
|
76
|
+
test_files: []
|
77
|
+
|