Created
March 9, 2012 16:09
-
-
Save mcansky/2007273 to your computer and use it in GitHub Desktop.
using iron.io workers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace :iron do | |
| desc "queue clockwork job at Iron worker" | |
| task :queue_clockwork => :environment do | |
| require "iron_worker_ng" | |
| client = IronWorkerNG::Client.new(Settings.iron_worker.token, Settings.iron_worker.project_id) | |
| # ...and upload it to iron.io cloud | |
| # :host, :port, :ssl, :payload, :url, :token, :username | |
| options = {:start_at => 30.seconds.since, :run_every => 300} | |
| options[:run_times] = ENV['COUNT'].to_i if ENV["COUNT"] | |
| params = {'host' => Settings.hostname.gsub("http://",''), 'port' => 443, | |
| 'ssl' => true, "url" => "/caboose/clockwork", :username => Settings.caboose.username, | |
| :token => Settings.caboose.token, :payload => {"data" => 1}} | |
| client.schedules.create('TestIron', params, options) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| desc "test" | |
| task :test do | |
| require "bundler" | |
| require 'YAML' | |
| require "iron_worker_ng" | |
| path = File.expand_path File.dirname(__FILE__) | |
| config = YAML::load( File.open("#{path}/config/config.yml") ) | |
| code = IronWorkerNG::Code::Ruby.new | |
| code.merge_worker("#{path}/workers/test_iron.rb") | |
| code.merge_gem('rails') | |
| #code.merge_gem('rest_client') # or how it's called? | |
| puts config['iron_worker']['token'] | |
| puts config['iron_worker']['project_id'] | |
| client = IronWorkerNG::Client.new(config['iron_worker']['token'], config['iron_worker']['project_id']) | |
| client.codes.create(code) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rest_client' | |
| require 'rails' | |
| require 'net/http' | |
| require "net/https" | |
| class BrawneReq | |
| def self.post(host, port, url, payload, token, username, ssl = false) | |
| http_r = Net::HTTP.new(host, port) | |
| http_r.use_ssl = ssl | |
| response = nil | |
| begin | |
| http_r.start() do |http| | |
| req = Net::HTTP::Post.new(url, initheader = {'Content-Type' =>'application/json'}) | |
| req.add_field("USERNAME", username) | |
| req.add_field("TOKEN", token) | |
| req.body = payload | |
| req.set_form_data(payload) | |
| response = http.request(req) | |
| end | |
| return [response.code, response.body] | |
| rescue Errno::ECONNREFUSED | |
| return [503, "unavailable"] | |
| end | |
| end | |
| end | |
| BrawneReq.post(@params['host'], @params['port'], @params['url'], @params['payload'], @params['token'], @params['username'], @params['ssl']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment