class ZuoraConnect::AppInstanceBase

def build_task(task_data, session)

### START Task Mathods ####
def build_task(task_data, session)
  @task_data = task_data
  @mode = @task_data["mode"]
  @task_data.each do |k,v|
    if k.match(/^(.*)_login$/)
      tmp = ZuoraConnect::Login.new(v)
      if session.present? && v["tenant_type"] == "Zuora"
        if tmp.entities.size > 0
          tmp.entities.each do |value|
            entity_id = value["id"]
            tmp.client(entity_id).current_session          = session["#{self.id}::#{k}::#{entity_id}:current_session"]               if session["#{self.id}::#{k}::#{entity_id}:current_session"]
            tmp.client(entity_id).bearer_token             = session["#{self.id}::#{k}::#{entity_id}:bearer_token"]                  if session["#{self.id}::#{k}::#{entity_id}:bearer_token"]
            tmp.client(entity_id).oauth_session_expires_at = session["#{self.id}::#{k}::#{entity_id}:oauth_session_expires_at"]      if session["#{self.id}::#{k}::#{entity_id}:oauth_session_expires_at"]
          end
        else
          tmp.client.current_session                       = session["#{self.id}::#{k}:current_session"]                             if session["#{self.id}::#{k}:current_session"]
          tmp.client.bearer_token                          = session["#{self.id}::#{k}:bearer_token"]                                if session["#{self.id}::#{k}:bearer_token"] && tmp.client.respond_to?(:bearer_token) ## need incase session id goes from basic to aouth in same redis store
          tmp.client.oauth_session_expires_at              = session["#{self.id}::#{k}:oauth_session_expires_at"]                    if session["#{self.id}::#{k}:oauth_session_expires_at"]  && tmp.client.respond_to?(:oauth_session_expires_at) 
        end
        @logins[k] = tmp
        self.attr_builder(k, @logins[k])
      elsif k == "options"
        v.each do |opt|
          @options[opt["config_name"]] = opt
        end
      elsif k == "user_settings"
        self.timezone =  v["timezone"]
        self.locale = v["local"]
      end
    end
  end
rescue => ex
  Rails.logger.error("Task Data: #{task_data}")
  Rails.logger.error("Task Session: #{session.to_hash}")
  raise
end