ROR Application Development Tips

I'm Ruby on Rails developer. I love to share my experience, technical knowledge. I work at Crypex Technologies which is developing applications in ROR for more than a decade.

Active Job in Rails

Ruby on Rails is the framework that provides the code to build most of the part of the application. When we develop the feature, the job is to write the parts of the application that help to perform a specific task. Ruby on Rails development contains different sub-framework to complete feature, one of them is Active Job. When rails application requires to perform the queuing backend job Active Job framework can be used to declare job and make it run.

The active job can be used to send emails, calculate billing, send notifications, scheduled clean-ups. It divides the job in small chunks and runs in parallel. Our effort is to provide the customers with a user-friendly and flexible web application.

This can be approached when server response time is effective. So put jobs that take more time of server to execute in a queue and serve in the backend. Scheduling the task in queue backend distribute traffic on the server by allowing to complete the job when the server is free.

To schedule backend job and run the job resque-scheduler, delayed_job gems can be used.

I worked on the project Google Review management that requires to send the notification to the users whenever there is a new google review comes in application. If I have performed send notification in real time to users that will decrease the response time of server. To achieve this, I found the solution to use Active Job framework.

How to create the Active job in rails?

Active Job framework has a rails generator to create job.

$ rails generate job email_notifier

Above will generate the below structure.

invoke test_unit

create test/jobs/email_notifier_job_test.rb

create app/jobs/email_notifier_job.rb

The created job will be shown as below

class EmailNotifierJob < ApplicationJob

queue_as :default

def perform(*emails)

# perform notification task

end

end

ApplicationJob is the base class for Active Job.

Keep Job in the Queue

Read the full blog here: https://goo.gl/Q9gYXA