module Isomorfeus module Operation module GenericClassApi def current_user Isomorfeus.current_user end if RUBY_ENGINE == 'opal' def _process_response(agent) agent.process do |agnt| agnt.response[:result] end if agent.result.key?(:rejected) if agent.result.key?(:error) e = agent.result[:error] exception_class_name = e[:class_name] exception_class = exception_class_name.constantize exception = exception_class.new(e[:message]) exception.set_backtrace(e[:backtrace]) raise exception else raise agent.result[:rejected] end else agent.result[:resolved] end end def promise_run(**props_hash) props = validated_props(props_hash) Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :run, props) .then { |agent| _process_response(agent) } end def promise_deferred(**props_hash) props = validated_props(props_hash) Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :deferred, props) .then { |agent| _process_response(agent) } end def promise_daily(**props_hash) key = props_hash.delete(:key) props = validated_props(props_hash) props[:key] = key if key Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :daily, props) .then { |agent| _process_response(agent) } end def promise_remove_daily(**props_hash) raise "key: must be given" unless props_hash.key?(:key) Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :remove_daily, props_hash) .then { |agent| _process_response(agent) } end def promise_daily_exist?(**props_hash) raise "key: must be given" unless props_hash.key?(:key) Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :daily_exist, props_hash) .then { |agent| _process_response(agent) } end else def promise_run(**props_hash) self.new(**props_hash).promise_run end def promise_deferred(**props_hash) props = validated_props(props_hash) task = Isomorfeus::Operation::DeferredTask.create(attributes: { operation_class_name: self.name, props: props, user_class_name: current_user.class.name, user_key: current_user.key, state: 'ready' }) Promise.new.resolve(task.key) end def promise_daily(**props_hash) key = props_hash.delete(:key) props = validated_props(props_hash) task = Isomorfeus::Operation::DailyTask.create(key: key, attributes: { operation_class_name: self.name, props: props, user_class_name: current_user.class.name, user_key: current_user.key, state: 'ready' }) Promise.new.resolve(task.key) end def promise_remove_daily(**props_hash) raise "key: must be given" unless props_hash.key?(:key) key = props_hash.delete(:key) Isomorfeus::Operation::DailyTask.destroy(key: key) Promise.new.resolve(true) end def promise_daily_exist?(**props_hash) raise "key: must be given" unless props_hash.key?(:key) key = props_hash.delete(:key) have_task = !!Isomorfeus::Operation::DailyTask.load(key: key) Promise.new.resolve(have_task) end end end end end