Skip to content

Commit

Permalink
Sanitization of options and version bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Apr 24, 2012
1 parent b838e58 commit 282520d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
gem.summary = %Q{New generation ruby client for IronWorker}
gem.email = "info@iron.io"
gem.authors = ["Andrew Kirilenko", "Iron.io, Inc"]
gem.files.exclude('.document', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'iron_worker_ng.gemspec')
gem.files.exclude('.document', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'iron_worker_ng.gemspec', 'test/**/**', 'examples/**/**')
end

Jeweler::RubygemsDotOrgTasks.new
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.3
0.3.4
10 changes: 5 additions & 5 deletions bin/iron_worker_ng → bin/iron_worker
Expand Up @@ -5,9 +5,9 @@ require 'time'
require 'iron_worker_ng'

if $*.size == 0 || (not ['codes.create', 'tasks.create', 'schedules.create', 'tasks.log'].include?($*[0]))
puts 'usage: iron_worker_ng COMMAND [OPTIONS]'
puts 'usage: iron_worker COMMAND [OPTIONS]'
puts ' COMMAND: codes.create, tasks.create, schedules.create, tasks.log'
puts ' run iron_worker_ng COMMAND --help to get more information about each command'
puts ' run iron_worker COMMAND --help to get more information about each command'
exit 1
end

Expand All @@ -27,7 +27,7 @@ if command == 'codes.create'
execute_features = []

opts = OptionParser.new do |opts|
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
opts.banner = "usage: iron_worker #{command} [OPTIONS]"

opts.on('-r', '--runtime RUNTIME', runtimes.map { |r| r[:name] }, "#{runtimes_help}") do |v|
runtime = v
Expand Down Expand Up @@ -87,7 +87,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
print_id = false

opts = OptionParser.new do |opts|
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
opts.banner = "usage: iron_worker #{command} [OPTIONS]"

opts.on('-n', '--name NAME', 'code name') do |v|
name = v
Expand Down Expand Up @@ -171,7 +171,7 @@ elsif command == 'tasks.log'
live = false

opts = OptionParser.new do |opts|
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
opts.banner = "usage: iron_worker #{command} [OPTIONS]"

opts.on('-t --task-id ID', 'task id') do |v|
task_id = v
Expand Down
26 changes: 5 additions & 21 deletions iron_worker_ng.gemspec
Expand Up @@ -5,14 +5,14 @@

Gem::Specification.new do |s|
s.name = "iron_worker_ng"
s.version = "0.3.3"
s.version = "0.3.4"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Andrew Kirilenko", "Iron.io, Inc"]
s.date = "2012-04-23"
s.date = "2012-04-24"
s.description = "New generation ruby client for IronWorker"
s.email = "info@iron.io"
s.executables = ["iron_worker_ng"]
s.executables = ["iron_worker"]
s.extra_rdoc_files = [
"LICENSE",
"README.md"
Expand All @@ -21,15 +21,7 @@ Gem::Specification.new do |s|
"LICENSE",
"README.md",
"VERSION",
"bin/iron_worker_ng",
"examples/ruby/hello/hello.rb",
"examples/ruby/hello/hello_worker.rb",
"examples/ruby/master_slave/master_slave.rb",
"examples/ruby/master_slave/master_worker.rb",
"examples/ruby/master_slave/slave_worker.rb",
"examples/ruby/simple/Gemfile",
"examples/ruby/simple/sample_worker.rb",
"examples/ruby/simple/simple.rb",
"bin/iron_worker",
"lib/iron_worker_ng.rb",
"lib/iron_worker_ng/api_client.rb",
"lib/iron_worker_ng/api_client_error.rb",
Expand All @@ -50,15 +42,7 @@ Gem::Specification.new do |s|
"lib/iron_worker_ng/feature/ruby/merge_gem.rb",
"lib/iron_worker_ng/feature/ruby/merge_gemfile.rb",
"lib/iron_worker_ng/logger.rb",
"lib/iron_worker_ng/version.rb",
"test/Gemfile",
"test/Rakefile",
"test/data/dir1/stub",
"test/data/dir2/test",
"test/hello.rb",
"test/helpers.rb",
"test/test_basic.rb",
"test/test_common_features.rb"
"lib/iron_worker_ng/version.rb"
]
s.homepage = "https://github.com/iron-io/iron_worker_ruby_ng"
s.require_paths = ["lib"]
Expand Down
63 changes: 41 additions & 22 deletions lib/iron_worker_ng/api_client.rb
Expand Up @@ -20,32 +20,33 @@ class APIClient

def initialize(options = {})
@token = options[:token] || options['token']
@token ||= ENV['IRON_IO_TOKEN']
@token ||= ENV['IRON_TOKEN']

@project_id = options[:project_id] || options['project_id']
@project_id ||= ENV['IRON_IO_PROJECT_ID']

if (@token.nil? || @project_id.nil?) && ((not options[:yaml_config_file].nil?) || (not options['yaml_config_file'].nil?))
load_yaml_config(options[:yaml_config_file] || options['yaml_config_file'])
end

if (@token.nil? || @project_id.nil?) && ((not options[:json_config_file].nil?) || (not options['json_config_file'].nil?))
load_json_config(options[:json_config_file] || options['json_config_file'])
end

if @token.nil? || @project_id.nil?
load_yaml_config('iron.yml')
end

if @token.nil? || @project_id.nil?
load_json_config('iron.json')
end

@token ||= ENV['IRON_TOKEN']
@project_id ||= ENV['IRON_PROJECT_ID']

if @token.nil? || @project_id.nil?
[ENV['IRON_IO_CONFIG'], ENV['IRON_IO_CONFIG_FILE'], ENV['IRON_CONFIG'], ENV['IRON_CONFIG_FILE'], '~/.iron', '/etc/iron.conf'].each do |config_file|
if (not config_file.nil?) && File.exists?(File.expand_path(config_file))
config = YAML.load_file(File.expand_path(config_file))

unless config['iron_io'].nil?
@token ||= config['iron_io']['token']
@project_id ||= config['iron_io']['project_id']
end

unless config['iron'].nil?
@token ||= config['iron']['token']
@project_id ||= config['iron']['project_id']
end

@token ||= config['token']
@project_id ||= config['project_id']
end
end
load_yaml_config('~/.iron.yml')
end

if @token.nil? || @project_id.nil?
load_json_config('~/.iron.json')
end

if (not @token) || (not @project_id)
Expand All @@ -64,6 +65,24 @@ def initialize(options = {})
@rest = Rest::Client.new
end

def load_yaml_config(config_file)
if File.exists?(File.expand_path(config_file))
config = YAML.load_file(File.expand_path(config_file))

@token ||= config['token']
@project_id ||= config['project_id']
end
end

def load_json_config(config_file)
if File.exists?(File.expand_path(config_file))
config = JSON.load(File.read(File.expand_path(config_file)))

@token ||= config['token']
@project_id ||= config['project_id']
end
end

def common_request_hash
{
'Content-Type' => 'application/json',
Expand Down
5 changes: 4 additions & 1 deletion lib/iron_worker_ng/client.rb
Expand Up @@ -105,14 +105,17 @@ def tasks_set_progress(task_id, options = {})
end

def tasks_wait_for(task_id, options = {})
options[:sleep] ||= 5
options[:sleep] ||= options['sleep'] || 5

task = tasks_get(task_id)

while task.status == 'queued' || task.status == 'running'
yield task if block_given?
sleep options[:sleep]
task = tasks_get(task_id)
end

task
end

def schedules_list(options = {})
Expand Down
12 changes: 7 additions & 5 deletions lib/iron_worker_ng/code/base.rb
Expand Up @@ -38,10 +38,6 @@ def initialize(*args, &block)
@name = nil
@features = []

if File.exists?('Workerfile')
eval(File.read('Workerfile'))
end

if args.length == 1 && args[0].class == String && File.exists?(args[0])
merge_exec(args[0])
elsif args.length == 1 && args[0].class == String
Expand All @@ -51,8 +47,14 @@ def initialize(*args, &block)

exec = args[0][:exec] || args[0]['exec'] || args[0][:worker] || args[0]['worker']
merge_exec(exec) unless exec.nil?
end

if args.length == 1 && args[0].class == Hash && ((not args[0][:workerfile].nil?) || (not args[0]['workerfile'].nil?))
eval(File.read(File.expand_path(args[0][:workerfile] || args[0]['workerfile'])))
else
raise "Wrong arguments" unless args.empty?
if File.exists?('Workerfile')
eval(File.read('Workerfile'))
end
end

unless block.nil?
Expand Down
19 changes: 2 additions & 17 deletions lib/iron_worker_ng/code/ruby.rb
Expand Up @@ -41,7 +41,6 @@ def create_runner(zip)
require 'json'
@iron_worker_task_id = task_id
@iron_task_id = task_id
@payload = File.read(payload_file)
Expand All @@ -52,10 +51,8 @@ def create_runner(zip)
rescue
end
@iron_io_token = parsed_payload['token'] || nil
@iron_token = @iron_io_token
@iron_io_project_id = parsed_payload['project_id'] || nil
@iron_project_id = @iron_io_project_id
@iron_token = parsed_payload['token'] || nil
@iron_project_id = parsed_payload['project_id'] || nil
@params = parsed_payload['params'] || {}
keys = @params.keys
Expand All @@ -67,26 +64,14 @@ def payload
@payload
end
def iron_worker_task_id
@iron_worker_task_id
end
def iron_task_id
@iron_task_id
end
def iron_io_token
@iron_io_token
end
def iron_token
@iron_token
end
def iron_io_project_id
@iron_io_project_id
end
def iron_project_id
@iron_project_id
end
Expand Down

0 comments on commit 282520d

Please sign in to comment.