iron_worker_ng 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -55,13 +55,15 @@ code.merge_gem 'activerecord'
55
55
 
56
56
  The IronWorkerNG::Code::Ruby class will help you package your code for upload, but to upload it to the cloud, you'll need to use the `IronWorkerNG::Client` class.
57
57
 
58
- ### initialize(name = nil)
58
+ ### initialize(*args)
59
59
 
60
- Create new code package with the specified name. If `name` is omitted, a camel-cased version of the worker's file name will be used.
60
+ Create new code package with the specified args.
61
61
 
62
62
  ```ruby
63
- code = IronWorkerNG::Code::Ruby.new
64
- code_with_name = IronWorkerNG::Code::Ruby.new('CoolWorker')
63
+ code_with_name = IronWorkerNG::Code::Ruby.new(:worker => 'cool_worker.rb', :name => 'CoolWorker')
64
+ code_with_guessed_name = IronWorkerNG::Code::Ruby.new(:worker => 'cool_worker.rb')
65
+ code_with_short_form_syntax = IronWorkeNG::Code::Ruby.new('cool_worker.rb')
66
+ code = IronWorkerNG::Code::Ruby.new # will need to use code.merge_worker later
65
67
  ```
66
68
 
67
69
  ### name()
@@ -72,6 +74,14 @@ Return the code package's name.
72
74
  puts code.name
73
75
  ```
74
76
 
77
+ ### name=(name)
78
+
79
+ Sets the code package's name.
80
+
81
+ ```ruby
82
+ code.name = 'CoolWorker'
83
+ ```
84
+
75
85
  ### hash_string()
76
86
 
77
87
  Return the hash string for the code package. If you want to prevent uploading unchanged code packages, you can use it to check if any changes were made. It's very efficient, so it shouldn't cause any performance impact.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -8,7 +8,7 @@ require_relative '../feature/common/merge_dir'
8
8
  module IronWorkerNG
9
9
  module Code
10
10
  class Base
11
- attr_reader :name
11
+ attr_accessor :name
12
12
  attr_reader :features
13
13
 
14
14
  @@registered_types = []
@@ -34,9 +34,18 @@ module IronWorkerNG
34
34
  include IronWorkerNG::Feature::Common::MergeFile::InstanceMethods
35
35
  include IronWorkerNG::Feature::Common::MergeDir::InstanceMethods
36
36
 
37
- def initialize(name = nil, options = {})
38
- @name = name
37
+ def initialize(*args)
38
+ @name = nil
39
39
  @features = []
40
+
41
+ if args.length == 1 && args[0].class == String && File.exists?(args[0])
42
+ merge_worker(args[0])
43
+ elsif args.length == 1 && args.class == String
44
+ @name = args[0]
45
+ elsif args.length == 1 && args.class == Hash
46
+ @name = args[0][:name]
47
+ merge_worker(args[0][:worker]) unless args[0][:worker].nil?
48
+ end
40
49
  end
41
50
 
42
51
  def fixate
@@ -36,7 +36,7 @@ root() {
36
36
 
37
37
  cd "$(root "$@")"
38
38
 
39
- java -cp #{classpath} #{worker.klass} "$@"
39
+ java -cp #{classpath} #{worker.klass.nil? ? "-jar #{File.basename(worker.path)}" : worker.klass} "$@"
40
40
  RUNNER
41
41
  end
42
42
  end
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module IronWorkerNG
2
4
  module Feature
3
5
  module Common
@@ -7,8 +9,10 @@ module IronWorkerNG
7
9
  attr_reader :dest
8
10
 
9
11
  def initialize(path, dest)
12
+ raise 'No such directory - ' + path unless Dir.exist? path
10
13
  @path = File.expand_path(path)
11
14
  @dest = dest
15
+ @dest = Pathname.new(dest).cleanpath.to_s + '/' unless @dest.empty?
12
16
  end
13
17
 
14
18
  def hash_string
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module IronWorkerNG
2
4
  module Feature
3
5
  module Common
@@ -9,6 +11,7 @@ module IronWorkerNG
9
11
  def initialize(path, dest)
10
12
  @path = File.expand_path(path)
11
13
  @dest = dest
14
+ @dest = Pathname.new(dest).cleanpath.to_s + '/' unless @dest.empty?
12
15
  end
13
16
 
14
17
  def hash_string
@@ -29,7 +29,7 @@ module IronWorkerNG
29
29
  module InstanceMethods
30
30
  attr_reader :worker
31
31
 
32
- def merge_worker(path, klass)
32
+ def merge_worker(path, klass = nil)
33
33
  @worker ||= nil
34
34
 
35
35
  unless @worker.nil?
@@ -37,7 +37,11 @@ module IronWorkerNG
37
37
  return
38
38
  end
39
39
 
40
- @name ||= klass.split('.')[-1]
40
+ if klass.nil?
41
+ @name ||= File.basename(path).gsub(/\.jar$/, '').capitalize.gsub(/_./) { |x| x[1].upcase }
42
+ else
43
+ @name ||= klass.split('.')[-1]
44
+ end
41
45
 
42
46
  @worker = IronWorkerNG::Feature::Java::MergeWorker::Feature.new(path, klass)
43
47
 
@@ -23,7 +23,7 @@ module IronWorkerNG
23
23
  groups = groups.map { |g| g.to_sym }
24
24
  groups << :default if groups.length == 0
25
25
 
26
- IronWorkerNG::Logger.info "Adding ruby gems dependencies from #{groups.join(', ')} group#{groups.size > 1 ? 's' : ''} of #{path}"
26
+ IronWorkerNG::Logger.info "Adding ruby gems dependencies from #{groups.join(', ')} group#{groups.length > 1 ? 's' : ''} of #{path}"
27
27
 
28
28
  specs = Bundler::Definition.build(path, path + '.lock', nil).specs_for(groups)
29
29
 
data/test/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'iron_worker_ng'
4
+ gem 'typhoeus'
5
+ gem 'pry'
data/test/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rake/testtask'
2
+ require 'tmpdir'
3
+
4
+ Dir.chdir(File.dirname(__FILE__) + '/..')
5
+
6
+ Rake::TestTask.new do |t|
7
+ examples_tests_dir = Dir.mktmpdir('iw_examples')
8
+
9
+ FileUtils::cp_r(Dir.glob('examples/*'), examples_tests_dir)
10
+
11
+ Dir.glob('examples/**/**.rb').each do |path|
12
+ next unless path =~ %r|examples/(.*)/([^/]+)/\2.rb$|
13
+
14
+ dir = $1
15
+ name = $2
16
+
17
+ test_path = examples_tests_dir + "/#{dir}/#{name}/test_example_#{name}.rb"
18
+
19
+ File.open(test_path, 'w') do |out|
20
+ out << "require 'helpers'\n"
21
+ out << "class #{name.capitalize}Test < Test::Unit::TestCase\n"
22
+ out << "def test_example\n"
23
+
24
+ File.readlines(path).each do |line|
25
+ line, assert_str = line.chomp.split /#>/
26
+ out << line << "\n"
27
+
28
+ if assert_str
29
+ cond, desc = assert_str.split /--/
30
+ out << "assert(" << cond << ", '" <<
31
+ (desc or "").gsub(/'/, "\\\\'") << "')\n"
32
+ end
33
+ end
34
+
35
+ out << "end\nend\n"
36
+ end
37
+ end
38
+
39
+ t.libs << "lib" << "test" << examples_tests_dir
40
+ files = FileList['test/**/**.rb',
41
+ examples_tests_dir + '/**/test_*.rb']
42
+ t.test_files = files.keep_if{ |f| f =~ Regexp.new(ENV['TESTP'] || '') }
43
+
44
+ t.verbose = true
45
+ end
File without changes
@@ -0,0 +1 @@
1
+ test
data/test/helpers.rb CHANGED
@@ -1 +1,46 @@
1
1
  require 'test/unit'
2
+ require 'tempfile'
3
+
4
+ require './lib/iron_worker_ng.rb'
5
+
6
+ def code_bundle(name,&block)
7
+ code = IronWorkerNG::Code::Ruby.new(name)
8
+
9
+ class << code
10
+ def worker_code(str)
11
+ tmpdir = Dir.tmpdir + '/' + Digest::MD5.hexdigest(str)
12
+ Dir.mkdir tmpdir unless Dir.exist? tmpdir
13
+
14
+ tmpfname = tmpdir + '/worker.rb'
15
+ File.open(tmpfname, "w") { |f| f << str }
16
+
17
+ puts "created #{tmpfname}"
18
+ merge_worker(tmpfname)
19
+ end
20
+ end
21
+
22
+ code.instance_eval(&block)
23
+
24
+ code
25
+ end
26
+
27
+ def inspect_zip(code)
28
+ zip_file = code.create_zip
29
+ yield Zip::ZipFile.open(zip_file)
30
+ File.unlink zip_file
31
+ end
32
+
33
+ class IWNGTest < Test::Unit::TestCase
34
+ attr_accessor :client
35
+
36
+ def setup
37
+ IronWorkerNG::Logger.logger.level = ::Logger::DEBUG
38
+
39
+ token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
40
+ raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
41
+ "environment variables") unless token and project_id
42
+
43
+ @client = IronWorkerNG::Client.new(:token => token,
44
+ :project_id => project_id )
45
+ end
46
+ end
data/test/test_basic.rb CHANGED
@@ -1,21 +1,7 @@
1
- require './lib/iron_worker_ng.rb'
2
- require 'test/unit'
1
+ require 'helpers'
3
2
 
4
- class BasicTest < Test::Unit::TestCase
5
- attr_accessor :client
6
-
7
- def setup
8
- IronWorkerNG::Logger.logger.level = ::Logger::DEBUG
9
-
10
- token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
11
- raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
12
- "environment variables") unless token and project_id
13
-
14
- @client = IronWorkerNG::Client.new(:token => token,
15
- :project_id => project_id )
16
- end
17
-
18
- def test_basic
3
+ class BasicTest < IWNGTest
4
+ def _test_basic
19
5
  code = IronWorkerNG::Code::Ruby.new('test_basic')
20
6
  code.merge_worker(File.dirname(__FILE__) + '/hello.rb')
21
7
  client.codes_create(code)
@@ -24,14 +10,4 @@ class BasicTest < Test::Unit::TestCase
24
10
  log = client.tasks_log(task_id)
25
11
  assert_equal( "hello\n", log, "worker stdout is in log" )
26
12
  end
27
-
28
- def test_30_codes
29
- 31.times do |i|
30
- code = IronWorkerNG::Code::Ruby.new("test_30_codes_code#{i}")
31
- code.merge_worker(File.dirname(__FILE__) + '/hello.rb')
32
- client.codes_create(code)
33
- end
34
- assert_equal( 31, client.codes_list.size )
35
- end
36
-
37
13
  end
@@ -0,0 +1,86 @@
1
+ require 'helpers'
2
+ require 'zip/zip'
3
+
4
+ class CommonFeaturesTest < IWNGTest
5
+
6
+ def test_merge_file
7
+ code = code_bundle('test') do
8
+ merge_file('test', 'test/data/dir2')
9
+ merge_worker('test/hello.rb')
10
+ end
11
+
12
+ inspect_zip(code) do |zip|
13
+ assert zip.find_entry('test/data/dir2/test')
14
+ end
15
+ end
16
+
17
+ def test_merge_file_no_dest
18
+ code = code_bundle('test') do
19
+ merge_file('Gemfile')
20
+ merge_worker('test/hello.rb')
21
+ end
22
+
23
+ inspect_zip(code) do |zip|
24
+ assert zip.find_entry('Gemfile')
25
+ end
26
+ end
27
+
28
+ def test_merge_dir_check
29
+ assert_raise RuntimeError, "should check if merged dir exists" do
30
+ code_bundle('test') do
31
+ merge_dir('dir2', 'test/data')
32
+ end
33
+ end
34
+ end
35
+
36
+ def test_merge_dir
37
+ code = code_bundle('test') do
38
+ merge_dir('test/data/dir2', 'test/data')
39
+ merge_worker('test/hello.rb')
40
+ end
41
+
42
+ inspect_zip(code) do |zip|
43
+ assert zip.find_entry('test/data/dir2/test')
44
+ end
45
+ end
46
+
47
+ def test_merge_dir_no_dest
48
+ code = code_bundle('test') do
49
+ merge_dir('test')
50
+ merge_worker('test/hello.rb')
51
+ end
52
+
53
+ inspect_zip(code) do |zip|
54
+ assert zip.find_entry('test/hello.rb')
55
+ end
56
+ end
57
+
58
+ def test_symlinks
59
+ File.unlink 'test/data/dir1/dir2' if
60
+ File.symlink? 'test/data/dir1/dir2'
61
+
62
+ Dir.chdir('test/data/dir1') do
63
+ File.symlink('../dir2', 'dir2')
64
+ end
65
+
66
+ code = code_bundle 'test_symlinks' do
67
+ merge_dir('test/data/dir1', 'test/data')
68
+ merge_dir('test/data/dir2', 'test/data')
69
+ worker_code 'puts File.read("test/data/dir1/dir2/test")'
70
+ end
71
+
72
+ inspect_zip(code) do |zip|
73
+ assert_equal '../dir2', zip.read('test/data/dir1/dir2')
74
+ end
75
+
76
+ client.codes_create(code)
77
+ task_id = client.tasks_create('test_symlinks').id
78
+ client.tasks_wait_for(task_id)
79
+ log = client.tasks_log(task_id)
80
+
81
+ assert_equal "test", log
82
+
83
+ File.unlink 'test/data/dir1/dir2'
84
+ end
85
+
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_worker_ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-15 00:00:00.000000000 Z
13
+ date: 2012-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zip
@@ -150,9 +150,14 @@ files:
150
150
  - lib/iron_worker_ng/feature/ruby/merge_worker.rb
151
151
  - lib/iron_worker_ng/logger.rb
152
152
  - lib/iron_worker_ng/version.rb
153
+ - test/Gemfile
154
+ - test/Rakefile
155
+ - test/data/dir1/stub
156
+ - test/data/dir2/test
153
157
  - test/hello.rb
154
158
  - test/helpers.rb
155
159
  - test/test_basic.rb
160
+ - test/test_common_features.rb
156
161
  homepage: https://github.com/iron-io/iron_worker_ruby_ng
157
162
  licenses: []
158
163
  post_install_message:
@@ -167,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
172
  version: '0'
168
173
  segments:
169
174
  - 0
170
- hash: 912710063
175
+ hash: -824880365
171
176
  required_rubygems_version: !ruby/object:Gem::Requirement
172
177
  none: false
173
178
  requirements: