CSC/ECE 517 Fall 2022 - E2273.Refactor delayed mailer.rb and scheduled task.rb
Background
Expertiza uses Sidekiq gem for asynchronous processing of email tasks. It has a queue system to hold and then process jobs. Sidekiq’s queue replaces DelayedMailer’s queue. The previous team that worked on this also created a method perform() to gather email IDs of all participants in an assignment and send them an email reminder. Some test cases exist for this work.
History: Previous projects
* E2253 [1] * E2144 [2]
About Assignment Controller
This class is responsible for the creation and implementation of assignment forms. This includes due dates, questionnaires and assigning reviews.
Previous Information can be found here E2144
Files Involved (some changed should not have been changed):
- app/controllers/assignments_controller.rb
- app/mailers/mail_worker.rb
- app/models/assignment_form.rb
- config/sidekiq.yml
- spec/models/assignment_form_spec.rb
- spec/sidekiq_mail_worker_spec.rb
- spec/spec_helper.rb
Problems and planned changes
We are planning to accomplish the following tasks in this project:
Problem 1: Refactor the create method in assignment_controller.rb file
* Proposed Solution: Split the whole function into multiple methods performing specific tasks. Change the name of the variables to meaningful names in the method. * Solution Implemented: Refactored the create method to split tasks into different methods and renamed a variable to correctly reflect its purpose.
# create a new assignment via the assigment form if the new assignment name and directory doesn't exist def assignment_creation_success @assignment_form.create_assignment_node exist_assignment = Assignment.find(@assignment_form.assignment.id) assignment_form_params[:assignment][:id] = exist_assignment.id.to_s if assignment_form_params[:assignment][:directory_path].blank? # No existing assignment for assignment form assignment_form_params[:assignment][:directory_path] = "assignment_#{assignment_form_params[:assignment][:id]}" end assignment_form_params[:assignment_questionnaire] = assign_questionnaire_array(exist_assignment) assignment_form_params[:due_date] = assign_due_date_array(exist_assignment) @assignment_form.update(assignment_form_params, current_user) assignment_id = Assignment.find(@assignment_form.assignment.id).id ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}" redirect_to edit_assignment_path assignment_id undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ") end # raises a flash error messgae when it fails to create an assignment and redirect to assignement/new page def assignemnt_creation_failure(existing_assignment, dir_path, existing_directory) flash[:error] = 'Failed to create assignment.' if existing_assignment flash[:error] << '<br> ' + @assignment_form.assignment.name + ' already exists as an assignment name' end if existing_directory flash[:error] << '<br> ' + dir_path + ' already exists as a submission directory name' end redirect_to '/assignments/new?private=1' end
Problem 2: Refactor the edit_params_setting method in assignment_controller.rb file
* Proposed Solution: Split the whole function into multiple methods performing specific tasks.
Problem 3: Increase the test coverage for sidekiq_mail_worker_spec.rb
* Proposed Solution: Add more tests to increase test coverage.