<commit_before>require 'iron_worker_ng'

IronCore::Logger.logger.level = ::Logger::DEBUG

# initializing client object
client = IronWorkerNG::Client.new(# optinal
                                  :scheme => 'https',
                                  :port => 443,
                                  :api_version => 2,
                                  :host => 'worker-aws-us-east-1.iron.io')

# creating code bundle

path = File.dirname(__FILE__) + '/sample_worker.rb'

# if not specified, name default to worker name converted from underscore to camel style
code = IronWorkerNG::Code::Base.new do
  merge_exec path
end
#> code.name == 'SampleWorker'

# still can pass name in constructor and exec
code = IronWorkerNG::Code::Base.new do
  name 'transmogrify'
  exec path
end
#> code.name == 'transmogrify'

# or in block (like other intance methods)
code = IronWorkerNG::Code::Base.new do
  name 'transmogrify'
  merge_exec path
end

# once worker merged, following attempts will be ignored
code.merge_exec('anything')
#> code.features.find{|f| f.is_a? IronWorkerNG::Feature::Ruby::MergeExec::Feature }.path.end_with? '/worker.rb'

# if worker requires some gems,
# we can specify worker dependency on gem
code.merge_gem('jeweler2')
# or on Gemfile, which is recommended
code.merge_gemfile(File.dirname(__FILE__) + '/Gemfile',
                   :default, :extra)
# all those dependencies will be resolved using bundler gem

# upload code bundle to iron.io
client.codes_create(code)

# we can retrive code packages list
codes = client.codes_list
#> codes.map{|c| c.name}.include?('transmogrify')

code_info = codes.find{|c| c.name == 'transmogrify'}
# other way to get such info is codes.get:
same_code_info = client.codes_get(code_info.id)
#> same_code_info == code_info

# create task to run the bundle
task_id = client.tasks_create('transmogrify').id

# wait for the task to finish
client.tasks_wait_for(task_id)
<commit_msg>fix ruby example 'simple' (#86)<commit_after>require 'iron_worker_ng'

IronCore::Logger.logger.level = ::Logger::DEBUG

# initializing client object
client = IronWorkerNG::Client.new(# optinal
                                  :scheme => 'https',
                                  :port => 443,
                                  :api_version => 2,
                                  :host => 'worker-aws-us-east-1.iron.io')

# creating code bundle

path = File.dirname(__FILE__) + '/sample_worker.rb'

# if not specified, name default to worker name converted from underscore to camel style
code = IronWorkerNG::Code::Base.new do
  merge_exec path
end

# still can pass name in constructor and exec
code = IronWorkerNG::Code::Base.new do
  name 'transmogrify'
  exec path
end
#> code.name == 'transmogrify'

# or in block (like other intance methods)
code = IronWorkerNG::Code::Base.new do
  name 'transmogrify'
  merge_exec path
end

# once worker merged, following attempts will be ignored
code.merge_exec('anything')
#> code.features.find{|f| f.is_a? IronWorkerNG::Feature::Ruby::MergeExec::Feature }.path.end_with? '/worker.rb'

# if worker requires some gems,
# we can specify worker dependency on gem
code.merge_gem('jeweler2')
# or on Gemfile, which is recommended
code.merge_gemfile(File.dirname(__FILE__) + '/Gemfile',
                   :default, :extra)
# all those dependencies will be resolved using bundler gem

# upload code bundle to iron.io
client.codes_create(code)

# we can retrive code packages list
codes = client.codes_list(:per_page => 100)
#> codes.map{|c| c.name}.include?('transmogrify')

code_info = codes.find{|c| c.name == 'transmogrify'}
# other way to get such info is codes.get:
same_code_info = client.codes_get(code_info.id)
#> same_code_info == code_info

# create task to run the bundle
task_id = client.tasks_create('transmogrify').id

# wait for the task to finish
client.tasks_wait_for(task_id)

{'fraction_non_alphanumeric': 0.11105358529640176, 'fraction_numerical': 0.004400724825265338, 'mean_word_length': 3.4413793103448276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370870', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1173, 'n_words': 347}