Sha256: 4349e5277c011f3c765a3e2230b79774b0cb9bc89cccdc3fcef8f0cbf9c57cf3

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 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 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)
        swf_client.respond_activity_task_completed({
          task_token: token,
          result: result,
        })
      end


      def failed!(exception)
        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

1 entries across 1 versions & 1 rubygems

Version Path
jflow-0.2.6 lib/jflow/activity/task.rb