Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AsyncAddList to Invoice #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

prburke
Copy link
Contributor

@prburke prburke commented Mar 4, 2015

Added AsyncAddList action to Invoice. Also added basic infrastructure that can be extended to support other asynchronous requests (e.g. NetSuite::Async::Status, NetSuite::Async::WriteResponseList, etc.)

Here is a simplified example of how it can be used:

job_status = NetSuite::Records::Invoice.async_add_list([invoices])
if job_status
  begin
    job_status = NetSuite::Async::Status.get(job_id: job_status.job_id)
    ...
  end until job_status.finished?
  response = NetSuite::Async::WriteResponseList.get(job_id: job_id)
  ...
end

@prburke prburke force-pushed the upstream_async_add_list branch from be56426 to 266833f Compare March 4, 2015 21:35
@prburke prburke force-pushed the upstream_async_add_list branch from 266833f to d735007 Compare March 5, 2015 14:37
@iloveitaly
Copy link
Member

@prburke could you add the usage example to the readme? Thanks for the PR!

@iloveitaly
Copy link
Member

@prburke would love to get this (and any other PRs you have) merged—could you update the readme with some examples of how to use this?

@diegopolido
Copy link

Hey @iloveitaly how is it going?

I did something like this:

module Commerce
  module NetSuite
    class AsyncJobStatus < ::Commerce::BaseJob
      queue_as :low

      def perform(job_id, transaction_type_class_name)
        job_status = ::NetSuite::Async::Status.get(job_id: job_id)

        if job_status.finished?
          response = ::NetSuite::Async::WriteResponseList.get(job_id: job_id)

          if response.list&.first&.status&.is_success
            transaction_type_class_name.constantize.new.audit
          else
            ::Raven.capture_message(
              "Failed sending #{transaction_type_class_name} report",
              extra: { message: response.list&.first&.status&.details&.first&.message }
            )
          end
        else
          ::Commerce::NetSuite::AsyncJobStatus.set(wait: 10.minutes).perform_later(job_id, transaction_type_class_name)
        end
      end
    end
  end
end

and I enqueue this job after send the record:

      def async_add_record_object
        return unless first_row

        job_status = record_object.class.async_add_list([record_object])

        ::Commerce::NetSuite::AsyncJobStatus.set(wait: 10.minutes).perform_later(job_status.job_id, self.class.name)
      end

@iloveitaly
Copy link
Member

@diegopolido could you collaborate on this PR and add some examples to the readme? Would be great to get a simplified version of what you posted above in the core readme.

@diegopolido
Copy link

I would need @prburke permissions to add code on this PR, right? I can do on a separated PR, what do you think?

@iloveitaly
Copy link
Member

@diegopolido if he didn't allow collaborators to add to this PR, then that would be true. A separate PR is fine—let's just link it to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants