Added AsyncAddList to Invoice
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 could you add the usage example to the readme? Thanks for the PR!
@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?
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
@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.
I would need @prburke permissions to add code on this PR, right? I can do on a separated PR, what do you think?
@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.