We've moved discussions to Discord

Rails Experts - I need your help understanding the way that ActionMailer, (Using SparkPost), and Sidekiq work together

Brandon B.
Background: I come from C# and Python years ago, i.e.: explicit is better than implicit (which may or may not be true these days with so many layers of wrappers)

Issue, everything is working for my mailers and sidekiq queues, etc., however, I can not understand how this is getting processed and am trying to figure out the way the 'magic' in ROR and Jumpstart is doing this. I understand ActionMailer, Sparkpost Rest API and Sidekiq all perfectly fine, independently, but cannot figure out how my mail is being processed, delivered, and queued.

I am just looking for someone to let me know what classes are calling the other classes and when 'the proverbial baton' is being passed between the classes, and possible responses.

For now I am simply calling the mailer from a button that fires a controller action.  The best I can presume is that the controller sends the call to the mailer (I called the class TestMailer and the method is sample_mail), however in the mailer class I am using 'simple_spark' gem (good gem if you are using sparkpost and rails 6) to create and send the 'transmission' - which gives me a response object(hash), in which I get back(an object like this): 
returns: {"total_rejected_recipients"=>0, "total_accepted_recipients"=>1, "id"=>"607605236307844073"}
from the controller I am printing the mail object that I am calling and get this:
Calling post
{data object sent to sparkpost with body content and params}
Response 200
#<Excon::Response:0x00007fedeb8617e0>
TestMailer#sample_email: processed outbound mail in 737.5ms
#<ActionMailer::Base::NullMail:0x00007fedeb860188>

Can someone please explain how this process-flow is working.  The reason I need a better grasp is because I am creating an internal email campaign application and this 'unknowing' works fine while I am testing this (and it is working fine) however, when I am queueing up 4,000-20,000 emails in a day, and I don't know exactly how this is called and queued, I could see a serious issue happening and I won't know how to fix it.

Like I said, I understand sidekiq and how to create and queue and prioritize activejobs, but I am having trouble understanding how Rails mailer is automatically, magically, plugging into sidekiq and how that is working.

Thanks in advance
Brandon B.
Ok, just for anyone that ends up reading this post and has a similar issue, I ended going more in-depth with my knowledge of sidekiq and how the events are triggered/queued/etc. and what all can be done from the activejob aspect of passing these classes around.

One major thing that I have realized is to keep the sidekiq jobs as lightweight and simple on the 'call' as possible.  The job can be more complex but the call should be able to be passed as JSON (as literally that is what it will be) so do not pass ruby/rails objects, rather pass their ids and make a model call after it is received on the other side.  In addition, the layers or priority for queuing is really what I was trying to figure out and I figured out how to customize that and make the calls and use sidekiq queues more properly as well.  

It's a weird paradox that I was avert to using sidekiq for a while now, and now that I did it for this application I am working on, and really am getting under the hood of sidekiq and redis I now want to move plenty of methods to sidekiq for background processing.  
Brandon B.
Background: I come from C# and Python years ago, i.e.: explicit is better than implicit (which may or may not be true these days with so many layers of wrappers)

Issue, everything is working for my mailers and sidekiq queues, etc., however, I can not understand how this is getting processed and am trying to figure out the way the 'magic' in ROR and Jumpstart is doing this. I understand ActionMailer, Sparkpost Rest API and Sidekiq all perfectly fine, independently, but cannot figure out how my mail is being processed, delivered, and queued.

I am just looking for someone to let me know what classes are calling the other classes and when 'the proverbial baton' is being passed between the classes, and possible responses.

For now I am simply calling the mailer from a button that fires a controller action.  The best I can presume is that the controller sends the call to the mailer (I called the class TestMailer and the method is sample_mail), however in the mailer class I am using 'simple_spark' gem (good gem if you are using sparkpost and rails 6) to create and send the 'transmission' - which gives me a response object(hash), in which I get back(an object like this): 
returns: {"total_rejected_recipients"=>0, "total_accepted_recipients"=>1, "id"=>"607605236307844073"}
from the controller I am printing the mail object that I am calling and get this:
Calling post
{data object sent to sparkpost with body content and params}
Response 200
#<Excon::Response:0x00007fedeb8617e0>
TestMailer#sample_email: processed outbound mail in 737.5ms
#<ActionMailer::Base::NullMail:0x00007fedeb860188>

Can someone please explain how this process-flow is working.  The reason I need a better grasp is because I am creating an internal email campaign application and this 'unknowing' works fine while I am testing this (and it is working fine) however, when I am queueing up 4,000-20,000 emails in a day, and I don't know exactly how this is called and queued, I could see a serious issue happening and I won't know how to fix it.

Like I said, I understand sidekiq and how to create and queue and prioritize activejobs, but I am having trouble understanding how Rails mailer is automatically, magically, plugging into sidekiq and how that is working.

Thanks in advance
Brandon B.
Ok, just for anyone that ends up reading this post and has a similar issue, I ended going more in-depth with my knowledge of sidekiq and how the events are triggered/queued/etc. and what all can be done from the activejob aspect of passing these classes around.

One major thing that I have realized is to keep the sidekiq jobs as lightweight and simple on the 'call' as possible.  The job can be more complex but the call should be able to be passed as JSON (as literally that is what it will be) so do not pass ruby/rails objects, rather pass their ids and make a model call after it is received on the other side.  In addition, the layers or priority for queuing is really what I was trying to figure out and I figured out how to customize that and make the calls and use sidekiq queues more properly as well.  

It's a weird paradox that I was avert to using sidekiq for a while now, and now that I did it for this application I am working on, and really am getting under the hood of sidekiq and redis I now want to move plenty of methods to sidekiq for background processing.  
Notifications
You’re not receiving notifications from this thread.
© 2023 Jumpstart Pro by GoRails, LLC