def codes_create(code, options = {})
      IronCore::Logger.debug 'IronWorker', "Calling codes.create with code='#{code.to_s}' and options='#{options.to_s}'"

      if options[:config] && options[:config].is_a?(Hash)
        options = options.dup
        options[:config] = options[:config].to_json
      end

      options.merge!(stack:code.stack) if code.stack

      container_file = code.create_container

      if code.zip_package
        res = nil
        IronWorker::Fetcher.fetch_to_file(code.zip_package) do |file|
          res = @api.codes_create(code.name, file, 'sh', '__runner__.sh', options)
        end
      elsif code.remote_build_command.nil? && (not code.full_remote_build)
        res = @api.codes_create(code.name, container_file, 'sh', '__runner__.sh', options)
      else
        builder_code_name = code.name + (code.name[0 .. 0].upcase == code.name[0 .. 0] ? '::Builder' : '::builder')

        @api.codes_create(builder_code_name, container_file, 'sh', '__runner__.sh', options)

        builder_task = tasks.create(builder_code_name, :code_name => code.name, :client_options => @api.options.to_json, :codes_create_options => options.to_json)

        builder_task = tasks.wait_for(builder_task._id)

        if builder_task.status != 'complete'
          log = tasks.log(builder_task._id)

          File.unlink(container_file)

          IronCore::Logger.error 'IronWorker', "Error while remote building worker\n" + log, IronCore::Error
        end

        res = JSON.parse(builder_task.msg)
      end

      File.unlink(container_file) if code.zip_package.nil?

      res['_id'] = res['id']
      OpenStruct.new(res)
    end
def codes_create(code, options = {})
      IronCore::Logger.debug 'IronWorker', "Calling codes.create with code='#{code.to_s}' and options='#{options.to_s}'"

      if options[:config] && options[:config].is_a?(Hash)
        options = options.dup
        options[:config] = options[:config].to_json
      end

      options.merge!(stack:code.stack) if code.stack

      container_file = code.create_container

      if code.zip_package
        res = nil
        IronWorker::Fetcher.fetch_to_file(code.zip_package) do |file|
          res = @api.codes_create(code.name, file, 'sh', '__runner__.sh', options)
        end
      elsif code.remote_build_command.nil? && (not code.full_remote_build)
        res = @api.codes_create(code.name, container_file, 'sh', '__runner__.sh', options)
      else
        builder_code_name = code.name + (code.name[0 .. 0].upcase == code.name[0 .. 0] ? '::Builder' : '::builder')

        @api.codes_create(builder_code_name, container_file, 'sh', '__runner__.sh', options)

        builder_task = tasks.create(builder_code_name, :code_name => code.name, :client_options => @api.options.to_json, :codes_create_options => options.to_json)

        builder_task = tasks.wait_for(builder_task._id)

        if builder_task.status != 'complete'
          log = tasks.log(builder_task._id)

          File.unlink(container_file)

          IronCore::Logger.error 'IronWorker', "Error while remote building worker\n" + log, IronCore::Error
        end

        res = JSON.parse(builder_task.msg)
      end

      File.unlink(container_file) if code.zip_package.nil?

      res['_id'] = res['id']
      OpenStruct.new(res)
    end
TODO: we should remove all this, legecy stuff.