require 'sidekiq' require 'date' include Sidekiq::Worker module JobsActions class Actions < ActiveJob::Base sidekiq_options queue: 'action_queue' def perform (object_id,rule_id) puts "SendAction" rule = Rule.find(rule_id) object = rule.rule_model.classify.constantize.find(object_id) actions = rule.action.where(:active? => true) actions.each do |action| action_type = action.action_type puts "Select Action #{action_type}" begin JobsActions::Actions.send(action_type,object,rule,action.action_params) rescue StandardError => e puts e end end end def self.callback(object,rule,action_params) puts "callback" action_params = JSON.parse(action_params) url = action_params["url"] attributes = action_params["attr"] servidor = Forcast::Utils::Server::Server.new do |config| config.dns = url config.connect = 1 config.write = 1 config.read = 1 #config.ssl = true #config.headers.store("accept","application/json") config.before_ping = false end model_id = object.attributes.slice(*attributes) unless attributes.include?("all") json_send = {:data => model_id} servidor.conexion(:post,{},"",json_send) end def self.telegram(object,rule,action_params) puts "telegram" end def self.slack(object,rule,action_params) puts "slack" end def self.email(object, rule, action_params) puts "action_params" puts action_params # attributes = action_params["attributes"] # model_id_attributes = object.attributes.slice(*attributes) unless attributes.include?("all") # model_id_attributes ||= object.attributes obj_identifier = action_params['attr_id'] ? object.send(action_params['attr_id']) : object.id Forcast::Utils::Email::Layout.with( to: action_params['owner_email'], cc: action_params['target_email'] ).default( object: object, rule: rule, obj_identifier: obj_identifier ).deliver_now end def self.notification(action_params); end def self.sms(action_params); end end end