Sha256: f1fcd03d2ad6de574c4e1d31e6e5169162b05143327b131f54aba21396fa7a11

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'json'
require 'logger'
require "base64"

require "prepare-environment"
require "trace-runner"

class HelperRun
    def run (solution, action, parameters)

        log = Logger.new(Canzea::config[:logging_root] + '/helpers.log')

        # Type can be either: ruby or shell
        # type = ARGV[0]
        type = "ruby"

        params = JSON.parse(parameters);
        # If there is context information, then merge them into the parameters before calling the helper
        if (ENV.has_key?('WORK_DIR') and File.exists?ENV['WORK_DIR'] + "/context.json")
            context = JSON.parse(File.read(ENV['WORK_DIR'] + "/context.json"))
            context.keys.each do |key|
               params[key] = context[key]
            end
        end

        # Make sure the parameters are valid JSON
        parameters = JSON.generate(params)

        envPush = PrepareEnvironment.new

        begin
            envScript = ENV['CANZEA_PLUGINS'] + "ike-environments/environment/production/helpers/#{solution}/environment.json"
            if File.exist?(envScript)
                log.info("Adding environment variables...")
                envPush.addToEnv "#{envScript}"
            end

            r = RunnerWorker.new

            if (type == "ruby")
                cmd = "ruby #{ENV['CANZEA_PLUGINS']}ike-environments/environment/production/helpers/#{solution}/#{action}.rb '#{parameters}'"
            else
                cmd = "#{ENV['CANZEA_PLUGINS']}ike-environments/environment/production/helpers/#{solution}/#{action}.sh \"#{parameters}\""
            end
            r.run cmd, 1, 1, false

        rescue => error
            log.error(error.backtrace)
            log.error("Error processing #{error.message}")
            abort("Problem running plan #{error.message}")
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canzea-0.1.1 lib/helper-run-class.rb
canzea-0.1.0 lib/helper-run-class.rb