Sha256: b601247a67c7cee5b2ee5485c59cdb47f422d1a6d0d1fce0f0c25d2d6c409ace

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

module JFlow
  module Activity
    class Task

      attr_reader :task

      def initialize(task)
        @task = task
      end

      def input
        YAML.load(task.input)
      end

      def name
        task.activity_type.name
      end

      def version
        task.activity_type.version
      end

      def token
        task.task_token
      end

      def run_id
        task.workflow_execution.run_id
      end

      def workflow_id
        task.workflow_execution.workflow_id
      end

      def klass
        @klass_value ||= JFlow.configuration.activity_map.klass_for(name,version)
        raise "Could not find code to run for given activity" unless @klass_value
        @klass_value
      end

      def method
        if name.split('.').size > 1
          method = name.split('.').last
        else
          method = "process"
        end
      end

      def run!
        log "Started #{klass}##{method} with #{input}"

        result = klass.new.send(method, *input) || "done"
        log "Result is #{result.class} #{result}"
        completed!(result)
      end

      def completed!(result)
        log "Task Completed"
        swf_client.respond_activity_task_completed({
          task_token: token,
          result: result,
        })
      end


      def failed!(exception)
        log "Task Failed #{exception.message}"
        swf_client.respond_activity_task_failed({
          task_token: token,
          reason: exception.message,
          details: exception.backtrace ? exception.backtrace.join("\n") : "no stacktrace",
        })
      end

      private

      def swf_client
        JFlow.configuration
             .swf_client
      end

      def log(str)
        JFlow.configuration.logger.info "[#{Thread.current.object_id}] #{str}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jflow-0.3.4 lib/jflow/activity/task.rb
jflow-0.3.3 lib/jflow/activity/task.rb
jflow-0.3.2 lib/jflow/activity/task.rb
jflow-0.3.1 lib/jflow/activity/task.rb
jflow-0.3.0 lib/jflow/activity/task.rb
jflow-0.2.9 lib/jflow/activity/task.rb
jflow-0.2.8 lib/jflow/activity/task.rb