fnf 0.0.1

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 ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fnf.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
data/README.markdown ADDED
@@ -0,0 +1,27 @@
1
+ # Fire and Forget (FNF)
2
+
3
+
4
+ ## Intro
5
+
6
+ Fire and Forget replaces the need to write resque tasks or delayed jobs to fire off web requests (usually notification webhooks or a anti-spam service, like defensio or akismet). A single worker reads and executes web requests from a blocking named pipe, while clients queue up them up in a non blocking manner. It uses typhoeus internally to execute the web requests for maximum speed.
7
+
8
+ ## Usage (worker)
9
+
10
+ Start the server
11
+
12
+ ```fnf```
13
+
14
+ (add this to rc.local, or a startup script)
15
+
16
+ ## Usage (client, rails)
17
+
18
+ Add to gemfile, or vendor the gem
19
+
20
+ ```gem 'fnf'```
21
+
22
+ From a controller or model
23
+
24
+ ```Fnf::Client.queue({:post => "http://api.akismet.com/process", :params => { :thing => "2123" })```
25
+
26
+
27
+ ![Set and Forget It](http://naturallyalise.com/blog/wp-content/uploads/2011/03/set-it-and-forget-it-ronco-rotisserie.jpg)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/fnf ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << "./lib"
4
+ require "fnf"
5
+ Fnf::Worker.run
data/fnf.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fnf/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fnf"
7
+ s.version = Fnf::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Julio Capote"]
10
+ s.email = ["jcapote@gmail.com"]
11
+ s.homepage = "http://www.github.com/capotej/fnf"
12
+ s.summary = %q{Fire And Forget, a queue designed for disposable web requests}
13
+ s.description = %q{ Fire and Forget replaces the need to write resque tasks or delayed jobs to fire off web requests (usually notification webhooks or a anti-spam service, like defensio or akismet). A single worker reads and executes web requests from a blocking named pipe, while clients queue up them up in a non blocking manner. It uses typhoeus internally to execute the web requests for maximum speed.}
14
+
15
+ s.rubyforge_project = "fnf"
16
+
17
+ s.add_dependency 'daemons'
18
+ s.add_dependency 'mkfifo'
19
+ s.add_dependency 'ruby-fifo'
20
+ s.add_dependency 'typhoeus'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
data/fnf_test.rb ADDED
@@ -0,0 +1,4 @@
1
+ $: << "./lib"
2
+ require 'fnf'
3
+
4
+ Fnf::Client.queue(:get => "http://127.0.0.1:3000/asdd")
data/lib/fnf.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'typhoeus'
2
+ require 'daemons'
3
+ require 'fifo'
4
+ require 'json'
5
+
6
+ module Fnf
7
+ autoload :Connection, 'fnf/connection'
8
+ autoload :Worker, 'fnf/worker'
9
+ autoload :Client, 'fnf/client'
10
+ end
data/lib/fnf/client.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Fnf
2
+ class Client
3
+ attr_accessor :url, :verb, :params
4
+
5
+ def self.queue(hsh)
6
+ verb = get_verb(hsh)
7
+ url = hsh[verb]
8
+ params = hsh[:params]
9
+ pipe = Fifo.new('/tmp/fnfq')
10
+ pipe.puts [verb,url,params].to_json
11
+ end
12
+
13
+ def self.get_verb(hsh)
14
+ [:delete, :get, :post, :put, :head].each do |verb|
15
+ return verb if hsh[verb]
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ module Fnf
2
+ module Connection
3
+
4
+ ConnectionError = Class.new(StandardError)
5
+
6
+ extend self
7
+
8
+ def http
9
+ Typhoeus::Request
10
+ end
11
+
12
+ [:get, :post, :put, :delete].each do |verb|
13
+ define_method verb do |path, *args|
14
+
15
+ params = args.last || {}
16
+
17
+ http.send(verb, path, :params => params)
18
+
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Fnf
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fnf/worker.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Fnf
2
+ class Worker
3
+
4
+ def self.run
5
+ pipe = Fifo.new('/tmp/fnfq')
6
+ while contents = pipe.readline
7
+ begin
8
+ payload = JSON.parse(contents)
9
+ Connection.send(payload[0], payload[1], payload[2])
10
+ rescue
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fnf::Client do
4
+ describe "#get_verb" do
5
+
6
+ [:delete, :get, :post, :put, :head].each do |verb|
7
+
8
+ it "should extract #{verb}" do
9
+ Fnf::Client.get_verb(verb => "http://www.example.com").should equal(verb)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
data/spec/spec.opts ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require(:default, :test)
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fnf
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Julio Capote
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-20 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: daemons
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: mkfifo
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: ruby-fifo
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: typhoeus
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ description: " Fire and Forget replaces the need to write resque tasks or delayed jobs to fire off web requests (usually notification webhooks or a anti-spam service, like defensio or akismet). A single worker reads and executes web requests from a blocking named pipe, while clients queue up them up in a non blocking manner. It uses typhoeus internally to execute the web requests for maximum speed."
61
+ email:
62
+ - jcapote@gmail.com
63
+ executables:
64
+ - fnf
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - README.markdown
73
+ - Rakefile
74
+ - bin/fnf
75
+ - fnf.gemspec
76
+ - fnf_test.rb
77
+ - lib/fnf.rb
78
+ - lib/fnf/client.rb
79
+ - lib/fnf/connection.rb
80
+ - lib/fnf/version.rb
81
+ - lib/fnf/worker.rb
82
+ - spec/client_spec.rb
83
+ - spec/spec.opts
84
+ - spec/spec_helper.rb
85
+ has_rdoc: true
86
+ homepage: http://www.github.com/capotej/fnf
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: fnf
109
+ rubygems_version: 1.6.1
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Fire And Forget, a queue designed for disposable web requests
113
+ test_files: []
114
+