Skip to content
Browse files

Cleanup

  • Loading branch information...
1 parent 34caf19 commit e3c91f8a4ad68b4b75c55ee6621aee4c52fb4085 Andrew Kirilenko committed Jan 14, 2012
Showing with 34 additions and 327 deletions.
  1. +1 −1 Gemfile
  2. +3 −19 Gemfile.lock
  3. +0 −14 README.md
  4. +17 −0 app.rb
  5. +2 −11 config.ru
  6. +3 −0 controllers/main.rb
  7. +0 −61 hello.rb
  8. BIN static/images/ajax-loader.gif
  9. +0 −9 static/js/jquery.ba-dotimeout.min.js
  10. +0 −191 views/hello.erb
  11. +8 −0 views/index.erb
  12. +0 −21 workers/tweet_worker.rb
View
2 Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'
+
gem 'sinatra'
gem 'iron_worker'
gem 'iron_mq'
-gem 'twitter'
View
22 Gemfile.lock
@@ -1,13 +1,6 @@
GEM
remote: http://rubygems.org/
specs:
- activesupport (3.1.3)
- multi_json (~> 1.0)
- addressable (2.2.6)
- faraday (0.7.5)
- addressable (~> 2.2.6)
- multipart-post (~> 1.1.3)
- rack (< 2, >= 1.1.0)
iron_mq (1.2.8)
typhoeus
typhoeus
@@ -17,24 +10,16 @@ GEM
zip
zip
mime-types (1.17.2)
- multi_json (1.0.4)
- multipart-post (1.1.4)
rack (1.3.5)
rack-protection (1.1.4)
rack
rest-client (1.6.7)
mime-types (>= 1.16)
- simple_oauth (0.1.5)
sinatra (1.3.1)
- rack (>= 1.3.4, ~> 1.3)
- rack-protection (>= 1.1.2, ~> 1.1)
- tilt (>= 1.3.3, ~> 1.3)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
- twitter (2.0.2)
- activesupport (< 4, >= 2.3.9)
- faraday (~> 0.7)
- multi_json (~> 1.0)
- simple_oauth (~> 0.1)
typhoeus (0.3.3)
mime-types
zip (2.0.2)
@@ -46,4 +31,3 @@ DEPENDENCIES
iron_mq
iron_worker
sinatra
- twitter
View
14 README.md
@@ -1,14 +0,0 @@
-
-
-First you need a token and project_id from your Iron.io account. Login at http://www.iron.io
-to get it.
-
-To run in development, run:
-
- IRON_WORKER_TOKEN=my_token IRON_WORKER_PROJECT_ID=my_project_id rackup -p 3000 config.ru
-
-To run on heroku:
-
-- heroku addons:add iron_worker
-- heroku addons:add iron_mq
-
View
17 app.rb
@@ -0,0 +1,17 @@
+require 'rubygems'
+require 'sinatra'
+require 'iron_worker'
+require 'iron_mq'
+
+enable :sessions
+
+set :public_folder, File.dirname(__FILE__) + '/static'
+
+IronWorker.configure do |iwc|
+ iwc.token = ENV['IRON_WORKER_TOKEN']
+ iwc.project_id = ENV['IRON_WORKER_PROJECT_ID']
+end
+
+set :ironmq, IronMQ::Client.new('token' => ENV['IRON_WORKER_TOKEN'], 'project_id' => ENV['IRON_WORKER_PROJECT_ID'])
+
+require 'controllers/main'
View
13 config.ru
@@ -1,14 +1,5 @@
-require 'yaml'
-require 'iron_worker'
+$: << File.expand_path(File.dirname(__FILE__))
-#@config = YAML.load_file('config.yml')
+require 'app'
-IronWorker.configure do |iwc|
- iwc.token = ENV['IRON_WORKER_TOKEN']
- iwc.project_id = ENV['IRON_WORKER_PROJECT_ID']
- #iwc.token = @config['iron']['token']
- #iwc.project_id = @config['iron']['project_id']
-end
-
-require './hello'
run Sinatra::Application
View
3 controllers/main.rb
@@ -0,0 +1,3 @@
+get '*' do
+ erb :index
+end
View
61 hello.rb
@@ -1,61 +0,0 @@
-require 'sinatra'
-require_relative 'workers/tweet_worker'
-#require_relative ''
-
-enable :sessions
-set :public_folder, File.dirname(__FILE__) + '/static'
-set :ironmq, IronMQ::Client.new('token'=>ENV['IRON_WORKER_TOKEN'], 'project_id'=>ENV['IRON_WORKER_PROJECT_ID'])
-set :queue_name, "tweets"
-
-post '/run_tweet_worker' do
- worker = TweetWorker.new
- worker.token = ENV['IRON_WORKER_TOKEN']
- worker.project_id = ENV['IRON_WORKER_PROJECT_ID']
- puts "settings.queue_name=" + settings.queue_name
- worker.queue_name = settings.queue_name
- # todo: store worker id in session then ajax show progress
- worker.queue
-
- session[:worker_id] = worker.task_id
- puts 'worker_id in session=' + worker.task_id
- #worker.wait_until_complete
- #p worker.status
- #"status=" + worker.status.inspect
- redirect '/'
-end
-
-get '/worker_status' do
- puts 'worker_id in session? ' + session[:worker_id].inspect
- if session[:worker_id]
- status = IronWorker.service.status(session[:worker_id])
- puts "status=" + status.inspect
- ret = {}
- ret['msg'] = "Worker running"
- ret['task_id'] = session[:worker_id]
- ret['status'] = status["status"]
- if status["status"] != "queued" && status["status"] != "running"
- session[:worker_id] = nil
- end
- return ret.to_json
- else
- return {msg: "No worker running."}.to_json
- end
-end
-
-
-get '/' do
- if session[:worker_id]
- @running = true
- end
- @msg = settings.ironmq.messages.get(:queue_name=>settings.queue_name)
- @msg.delete if @msg
- erb :hello
-end
-
-get '*' do
- if request.host == "blog.simpleworker.com"
- redirect "#{request.scheme}://blog.iron.io#{request.path}"
- return true
- end
- redirect '/'
-end
View
BIN static/images/ajax-loader.gif
Deleted file not rendered
View
9 static/js/jquery.ba-dotimeout.min.js
@@ -1,9 +0,0 @@
-/*
- * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
- * http://benalman.com/projects/jquery-dotimeout-plugin/
- *
- * Copyright (c) 2010 "Cowboy" Ben Alman
- * Dual licensed under the MIT and GPL licenses.
- * http://benalman.com/about/license/
- */
-(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);
View
191 views/hello.erb
@@ -1,191 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset='utf-8'>
-
- <title>Powered by Iron.io</title>
-
- <style type="text/css">
- body {
- margin-top: 1.0em;
- font-family: Helvetica, Arial, FreeSans, san-serif;
- }
-
- a:visited {
- color: darkblue;
- }
-
- /*a:visited#main {*/
- /*color: red;*/
- /*}*/
-
- #container {
- margin: 0 auto;
- width: 800px;
- }
-
- h1 {
- font-size: 3.1em;
- margin-bottom: 3px;
- /*letter-spacing: -2px;*/
- }
-
- h1 .sw {
- color: #1e90ff;
- }
-
- h1 .iw {
- color: #b22222;
- }
-
- h1 .small {
- font-size: 0.4em;
- }
-
- h1 a {
- text-decoration: none
- }
-
- h2 {
- font-size: 1.5em;
- color: #1e90ff;
- }
-
- h3 {
- text-align: center;
- color: #1e90ff;
- }
-
- a {
- color: #1e90ff;
- }
-
- .description {
- font-size: 1.2em;
- margin-bottom: 30px;
- margin-top: 30px;
- }
-
- .download {
- float: right;
- }
-
- pre {
- background: #000;
- color: #fff;
- padding: 15px;
- }
-
- hr {
- border: 0;
- width: 80%;
- border-bottom: 1px solid #aaa
- }
-
- .footer {
- text-align: center;
- padding-top: 30px;
- font-style: italic;
- }
- </style>
-
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script type="text/javascript" src="/js/jquery.ba-dotimeout.min.js"></script>
-
-
-</head>
-
-<body>
-
-<br/><br/>
-
-<div id="container">
-
- <h1><a href="http://www.iron.io" id="main">Powered by Iron.io</a></h1>
-
- <p>
- This is an example application that uses <a href="http://www.iron.io/products/mq">IronMQ</a>
- and <a href="http://www.iron.io/products/worker">IronWorker</a> together. If you click
- the &quot;Run TweetWorker&quot; button below, that will queue up a
- <a href="https://github.com/iron-io/heroku_sinatra_example/blob/master/workers/tweet_worker.rb">TweetWorker</a> task
- on IronWorker. TweetWorker is a worker that gets the latest tweet tagged with #cloud and push that
- tweet onto a queue on IronMQ.
- <br/><br/>
- This page you are looking at grabs tweets off the same queue on IronMQ and displays them. To see
- more tweets, keep running TweetWorker.
- </p>
-
- <div>
- <% if @msg %>
- Latest Tweet:
- <br/>
- <span style="font-weight: bold;">
- <%= @msg.body %>
- </span>
- <% else %>
- <div style="color: red;">
- There are no more tweets in the queue. Run TweetWorker to get another one.
- </div>
- <% end %>
- </div>
-
- <div class="description">
- <form action="/run_tweet_worker" method="post">
- <button>Run TweetWorker</button>
- </form>
- </div>
-
- <script>
- var keep_going = true;
- $.doTimeout(2000, function () {
-
- var jqxhr = $.getJSON("/worker_status", function (json) {
-// alert("success");
- console.log("json");
- console.log(json);
- if (json.status != null) {
- $("#status_div").html("Task status: " + json.status);
- keep_going = true;
- } else {
- keep_going = false;
- $("#status_indicator").hide();
- }
- })
-// .success(function() { alert("second success"); })
- .error(function () {
- alert("error");
- keep_going = false;
- })
-// .complete(function() { alert("complete"); });
-
- return keep_going;
- });
- </script>
- <div id="status_container" style="display: none;">
- <div id="status_indicator" style="display: inline-block; width: 40px;">
- <img src="/images/ajax-loader.gif"/>
- </div>
- <div id="status_div">
-
- </div>
- </div>
-
- <script>
- <% if @running %>
- $("#status_container").show();
- <% else %>
- $("#status_container").hide();
- <% end %>
- </script>
-
-
- <div class="footer">
- Source code for this project is on
- <a href="https://github.com/iron-io/heroku_sinatra_example" target="_blank">Github</a>
- </div>
-
-</div>
-
-</body>
-</html>
-
View
8 views/index.erb
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+ Hello
+</body>
+</html>
View
21 workers/tweet_worker.rb
@@ -1,21 +0,0 @@
-
-class TweetWorker < IronWorker::Base
-
- merge_gem 'iron_mq'
- merge_gem 'twitter'
-
- attr_accessor :token, :project_id, :queue_name
-
- def run
- puts "Hello! I am Uber."
-
- tweet = Twitter.search("#cloud -rt").first.text
- puts "tweet=#{tweet}"
-
- ironmq = IronMQ::Client.new('token'=>token, 'project_id'=>project_id)
- response = ironmq.messages.post(tweet, :queue_name=>queue_name)
-
- puts "tweet put on queue. " + response.inspect
-
- end
-end

0 comments on commit e3c91f8

Please sign in to comment.
Something went wrong with that request. Please try again.