shake_n_bake 0.1.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 +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Rakefile +1 -0
- data/examples/simple.rb +17 -0
- data/lib/shake_n_bake/dsl.rb +66 -0
- data/lib/shake_n_bake/version.rb +3 -0
- data/lib/shake_n_bake.rb +12 -0
- data/readme.md +75 -0
- data/shake_n_bake.gemspec +21 -0
- metadata +71 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Tom Wilson
|
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/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/examples/simple.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'shake_n_bake'
|
3
|
+
|
4
|
+
ShakeNBake do
|
5
|
+
|
6
|
+
INTERVAL = 2
|
7
|
+
|
8
|
+
shake do
|
9
|
+
puts 'Enter a number'
|
10
|
+
STDIN.gets # return to bake
|
11
|
+
end
|
12
|
+
|
13
|
+
bake do |result|
|
14
|
+
puts result.to_i + 10 # add 10 to result
|
15
|
+
puts 'Cool, lets play again!'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# DSL for Shake n Bake
|
2
|
+
class ShakeNBake::DSL
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
# Setup Method for registering instance vars
|
6
|
+
def setup(&block)
|
7
|
+
self.instance_eval(&block) if block_given?
|
8
|
+
end
|
9
|
+
|
10
|
+
# Shake ping the queue or data your watching
|
11
|
+
def shake(&block)
|
12
|
+
@shake_proc = block if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
# Bake when result exec block
|
16
|
+
def bake(&block)
|
17
|
+
@bake_proc = block if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Start your engines!
|
21
|
+
def run
|
22
|
+
register_signal_handlers
|
23
|
+
loop do
|
24
|
+
break if shutdown?
|
25
|
+
result = self.instance_eval &@shake_proc
|
26
|
+
self.instance_exec(result, &@bake_proc) if result
|
27
|
+
sleep INTERVAL || 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
# FROM Resque::Worker
|
33
|
+
|
34
|
+
# Registers the various signal handlers a worker responds to.
|
35
|
+
#
|
36
|
+
# TERM: Shutdown immediately, stop processing jobs.
|
37
|
+
# INT: Shutdown immediately, stop processing jobs.
|
38
|
+
# QUIT: Shutdown after the current job has finished processing.
|
39
|
+
def register_signal_handlers
|
40
|
+
trap('TERM') { shutdown! }
|
41
|
+
trap('INT') { shutdown! }
|
42
|
+
begin
|
43
|
+
trap('QUIT') { shutdown }
|
44
|
+
rescue ArgumentError
|
45
|
+
warn "Signals QUIT, USR1, USR2, and/or CONT not supported."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Schedule this worker for shutdown. Will finish processing the
|
50
|
+
# current job.
|
51
|
+
def shutdown
|
52
|
+
puts 'Exiting...'
|
53
|
+
@shutdown = true
|
54
|
+
end
|
55
|
+
|
56
|
+
# Shutdown immediately.
|
57
|
+
def shutdown!
|
58
|
+
shutdown
|
59
|
+
end
|
60
|
+
|
61
|
+
# Should this worker shutdown as soon as current job is finished?
|
62
|
+
def shutdown?
|
63
|
+
@shutdown
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/shake_n_bake.rb
ADDED
data/readme.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# UNDER DEVELOPMENT #
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
# Shake-N-Bake
|
6
|
+
|
7
|
+
A very simple dsl that allows you to neatly watch for something
|
8
|
+
for a given Interval and then once the result is received and
|
9
|
+
valid the publish/write the result.
|
10
|
+
|
11
|
+
AKA.
|
12
|
+
|
13
|
+
# `Shake` ~ N ~ `Bake`
|
14
|
+
|
15
|
+
## Example 1 : Consuming a Job from a Cloudq
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
require 'shake_n_bake'
|
19
|
+
|
20
|
+
ShakeNBake do
|
21
|
+
|
22
|
+
INTERVAL = 2 # seconds
|
23
|
+
|
24
|
+
setup do
|
25
|
+
@cloudq = Cloudq::Consumer.new 'incoming_fax'
|
26
|
+
end
|
27
|
+
|
28
|
+
shake do
|
29
|
+
# watch a queue
|
30
|
+
@cloudq.get_job
|
31
|
+
end
|
32
|
+
|
33
|
+
bake do |job|
|
34
|
+
Fax.new(job[:args]).deliver
|
35
|
+
@cloudq.complete_job job.id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## Example 2 : Watching a local database and publishing a job
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
require 'sequel'
|
45
|
+
require 'chronic'
|
46
|
+
require 'cloudq'
|
47
|
+
require 'shake_n_bake'
|
48
|
+
|
49
|
+
ShakeNBake do
|
50
|
+
|
51
|
+
INTERVAL = 10 # seconds
|
52
|
+
|
53
|
+
setup do
|
54
|
+
# my db connection
|
55
|
+
end
|
56
|
+
|
57
|
+
shake do
|
58
|
+
# watch for change form a db
|
59
|
+
DB['select is_awesome from foo where chg_date < ?', Chronic.parse('10 seconds ago')].get
|
60
|
+
end
|
61
|
+
|
62
|
+
bake do |result|
|
63
|
+
# publish it to cloudq
|
64
|
+
Cloudq::Publish.new('awesome').job 'Person', :awesome => result
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
_If your not first your last_
|
72
|
+
|
73
|
+
`Shake` ~ N ~ `Bake`
|
74
|
+
|
75
|
+
See LICENSE.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "shake_n_bake/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "shake_n_bake"
|
7
|
+
s.version = ShakeNBake::VERSION
|
8
|
+
s.authors = ["Tom Wilson"]
|
9
|
+
s.email = ["tom@jackhq.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Shake and Bake is a simple dsl that allow you to check a system or service "Shake" then write or publish if there are results "bake"}
|
12
|
+
s.description = %q{Shake and Bake is a simple dsl that allow you to check a system or service "Shake" then write or publish if there are results "bake"}
|
13
|
+
|
14
|
+
s.rubyforge_project = "shake_n_bake"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_development_dependency('rspec')
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shake_n_bake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Wilson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-21 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &2156714620 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2156714620
|
26
|
+
description: Shake and Bake is a simple dsl that allow you to check a system or service
|
27
|
+
"Shake" then write or publish if there are results "bake"
|
28
|
+
email:
|
29
|
+
- tom@jackhq.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- .rvmrc
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- Rakefile
|
39
|
+
- examples/simple.rb
|
40
|
+
- lib/shake_n_bake.rb
|
41
|
+
- lib/shake_n_bake/dsl.rb
|
42
|
+
- lib/shake_n_bake/version.rb
|
43
|
+
- readme.md
|
44
|
+
- shake_n_bake.gemspec
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project: shake_n_bake
|
66
|
+
rubygems_version: 1.6.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Shake and Bake is a simple dsl that allow you to check a system or service
|
70
|
+
"Shake" then write or publish if there are results "bake"
|
71
|
+
test_files: []
|