Sha256: b38a09a81544b97cf872e6bd2c6587ec2f6852ded1c4aac0ee1b487433568f9a

Contents?: true

Size: 1.95 KB

Versions: 19

Compression:

Stored size: 1.95 KB

Contents

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

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

class HelperRun
    def initialize ()
        @basePath = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}/catalog"
        @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
    end

    def runPlan (plans)
        plans.each { | plan |
            puts "Running #{plan[:action]}"
            self.run plan[:solution], plan[:action], JSON.generate(plan[:parameters])
        }
    end

    def enrich (params)
        # 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"))
            result = JSON.parse(params).merge(context)
            return JSON.generate(result)
        end
        return params
    end

    def run (solution, action, parameters, status = false)

        type = "ruby"

        parameters = self.enrich(parameters)

        envPush = PrepareEnvironment.new

        begin
            envScript = "#{@basePath}/helpers/#{solution}/environment.json"
            if File.exist?(envScript)
                @log.info("Adding environment variables...")
                envPush.addToEnv "#{envScript}"
            end

            r = RunnerWorker.new

            ENV['CATALOG_LOCATION'] = "#{@basePath}";

            parameters = Template.new.processString(parameters, {})

            if (type == "ruby")
                cmd = "ruby #{@basePath}/helpers/#{solution}/#{action}.rb '#{parameters}'"
            else
                cmd = "#{@basePath}/helpers/#{solution}/#{action}.sh \"#{parameters}\""
            end
            r.run cmd, 1, 1, status

        rescue => exception
            @log.error(cmd)
            @log.error(exception.to_s)
            @log.error(exception.backtrace)
            abort()
        end
    end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
canzea-0.1.74 lib/helper-run-class.rb
canzea-0.1.73 lib/helper-run-class.rb
canzea-0.1.72 lib/helper-run-class.rb
canzea-0.1.71 lib/helper-run-class.rb
canzea-0.1.70 lib/helper-run-class.rb
canzea-0.1.68 lib/helper-run-class.rb
canzea-0.1.67 lib/helper-run-class.rb
canzea-0.1.66 lib/helper-run-class.rb
canzea-0.1.64 lib/helper-run-class.rb
canzea-0.1.63 lib/helper-run-class.rb
canzea-0.1.62 lib/helper-run-class.rb
canzea-0.1.61 lib/helper-run-class.rb
canzea-0.1.60 lib/helper-run-class.rb
canzea-0.1.59 lib/helper-run-class.rb
canzea-0.1.58 lib/helper-run-class.rb
canzea-0.1.57 lib/helper-run-class.rb
canzea-0.1.56 lib/helper-run-class.rb
canzea-0.1.55 lib/helper-run-class.rb
canzea-0.1.54 lib/helper-run-class.rb