Sha256: 32eae32f817578f961c5795b525db793c6084182c6ac0d0090cd2dcc43922756

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

require 'active_record'  
require 'rules_engine'

desc "run a rules engine plan"   
task :rules_engine do

  if ENV['re_plan'].blank?
    raise "usage: rake rules_engine re_plan=[plan code] re_param='[value]'"
  end    
        
  environment = ENV["RAILS_ENV"] || "development"

  dbconfig = YAML::load(File.open("#{File.dirname(__FILE__)}/../../config/database.yml"))[environment]    
  ActiveRecord::Base.establish_connection(dbconfig)
        
  RulesEngine::Publish.publisher = :db_publisher
  RulesEngine::Process.runner = :db_runner
  RulesEngine::Process.auditor = :db_auditor
  RulesEngine::Process.auditor.audit_level = RulesEngine::Process::AUDIT_INFO
  RulesEngine::Discovery.rules_path = File.expand_path(File.join(File.dirname(__FILE__), '/../../app/rules'))
  RulesEngine::Discovery.discover! 
  
  plan = RulesEngine::Publish.publisher.get(ENV['re_plan'])
  if plan.nil?
    raise "published plan \"#{ENV['re_plan']}\" not found"
  end    
    
  data = ENV.inject({}){ |data, value| data[value[0].sub(/^re_/, '').to_sym] = value[1] if value[0] =~ /^re_/; data }  
  process_id = RulesEngine::Process.runner.create  
  success = RulesEngine::Process.runner.run_plan(process_id, plan, data)
  
  # process = RulesEngine::Process.open(process.re_process.id)
      
  puts "plan #{success ? 'succeeded' : 'failed'} : process_id = #{process_id} : data = #{data.inspect}"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rules_engine-0.2.0 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.10 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.9 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.8 rails_generators/templates/lib/tasks/rules_engine.rake