E1835 Refactor delayed mailer and scheduled task: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:
4. Replaced the code that uses the existing DelayedMailer queue to incorporate Sidekiq's queue
4. Replaced the code that uses the existing DelayedMailer queue to incorporate Sidekiq's queue
5. Added RSPEC test cases to test the creation of assignment deadlines and background Sidekiq email job
5. Added RSPEC test cases to test the creation of assignment deadlines and background Sidekiq email job


== About Sidekiq ==
== About Sidekiq ==

Revision as of 03:04, 3 November 2018

About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments, modify existing assignments and set deadlines. The instructor can also create a list of project topics that the students can sign up for. Expertiza allows students to peer review submissions of other students as well as do teammate reviews. Students can form team on Expertiza to work on assignments and projects.

Problem Statement

The following tasks were accomplished in this project: 1. Used Sidekiq gem for asynchronous processing of email jobs 2. Created a new mailer class- MailWorker that uses Sidekiq's queue to hold and process jobs 3. Defined the perform method to extract the Email IDs of all participants of the corresponding assignment and send an email reminder 4. Replaced the code that uses the existing DelayedMailer queue to incorporate Sidekiq's queue 5. Added RSPEC test cases to test the creation of assignment deadlines and background Sidekiq email job

About Sidekiq

Sidekiq is a background processing framework for Ruby. It allows to scale our application by performing work in the background. In particular it consists of three parts: Client, Redis and Server. The client runs in Ruby process and allows us to create jobs for processing later. Once a job is created, a Hash representing that job is created and serialized to a Json String. This String is pushed into a queue in Redis. Redis provides data storage for Sidekiq and holds all the job data. Each Sidekiq server process pulls jobs from the queue in Redis and processes them.

Current Implementation

1. Uses the 'delayed_job_active_record' gem for asynchronous processing of delayed jobs The current implementation uses Delayed::Job for implementing a Database based asynchronous priority queue system for storing the job queue of email reminders corresponding to various deadline types. 2. Email reminders were sent to users corresponding to each deadline type The DelayedMailer class includes a perform method that finds Email IDs of the target users corresponding to the deadline type. The subject and body of the email message is then constructed and the delayed_message method of Mailer class is used for sending the emails out to the users. 3. Uses DelayedJob to enqueue email jobs The DelayedMailer object is enqueued into the DelayedJob queue using enqueue method. These jobs are meant to be executed as the deadline of the corresponding Email job approaches.

Drawbacks and Solutions

Problem 1: The perform method in the DelayedMailer class contains a big case statement to check each kind of deadline

The perform method in DelayedMailer class checks the deadline type individually using multiple if statements and populates the Email IDs of the target users by querying the database. Auxiliary methods like, for example, mail_signed_up_users is invoked which in turn calls the email_reminder method. This makes the implementation very cumbersome and does not follow the principles of DRY code as the same email_reminder method is called multiple times under different conditions.


Testing Details

RSpec

We found no existing test cases for the above two problem statements. So we are to define test cases which generate the list of unwanted Chinese non-UTF8 characters and also HTML tags in the views and then refactor our code so that it automatically removes them without any failing of functionalities.

References

  1. Link to the videos to see the steps followed for testing and resolving the problems: [1]