CSC/ECE 517 Fall 2021 - E2135 Email notification to reviewers and instructors: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(14 intermediate revisions by 3 users not shown)
Line 18: Line 18:


We use delayed jobs library to deal with the delayed email.  
We use delayed jobs library to deal with the delayed email.  
We need run following command in order to install delayed_job binary executable.
We need run following command in order to install '''delayed_job''' binary executable.


     rails generate delayed_job
     rails generate delayed_job
Line 30: Line 30:


     RAILS_ENV=development bin/delayed_job stop
     RAILS_ENV=development bin/delayed_job stop


==Implementation approach==
==Implementation approach==


'''1) Reminder email sent when assignment or review is approaching deadline:'''
'''1) Reminder email sent when assignment or review is approaching deadline:'''
In the due_date.rb file, whenever a new due date is created or an existing due date is updated, the 'start_reminder' method will be fired which will eventually be added to the delayed_job queue. This job will be executed at a preconfigured time before deadline, where it will fire the method 'reminder' which will be added to the delayed job queue by the handle_asynchronously method of gem 'delayed_job_active_record'. Inside the reminder method, we will fetch three attributes - assignment_id, deadline_type, due_at. These three attributes will be used to decide the deadline type ( submission or review or teammate review ), fetch the participant email for that assignment, fetch the deadline threshold and at the end send the email reminder at a specified threshold time before the deadline which will contain all the details such as assignment names link to assignment and assignment type ( submission or review or teammate review).  
In the '''due_date.rb''' file, whenever a new due date is created or an existing due date is updated, the '''start_reminder''' method will be fired which will eventually be added to the delayed_job queue. This job will be executed at a preconfigured time before the deadline, where it will fire the method '''reminder''' which will be added to the delayed job queue by the handle_asynchronously method of gem '''delayed_job_active_record'''. Inside the reminder method, we will fetch three attributes - '''''assignment_id''''', '''''deadline_type''''', '''''due_at'''''. These three attributes will be used to decide the deadline type ( submission or review or teammate review ), fetch the participant email for that assignment, fetch the deadline threshold and at the end send the email reminder at a specified threshold time before the deadline which will contain all the details such as assignment names link to assignment and assignment type ( submission or review or teammate review).  


'''2) Implement code:'''  
'''2) Implement code:'''  


    # TODO E2135. Email notification to reviewers and instructors
   def create_mailer_object
   def create_mailer_object
     Mailer.new
     Mailer.new
   end
   end
   def create_mailworker_object
   def create_mailworker_object
     MailWorker.new(self.parent_id, self.deadline_type, self.due_at)
     MailWorker.new(self.parent_id, self.deadline_type, self.due_at)
Line 64: Line 61:
     end
     end
   end
   end
 
  ####
   def reminder
   def reminder
     deadline_text = self.deadline_type if %w[submission review].include? self.deadline_type
     deadline_text = self.deadline_type if %w[submission review].include? self.deadline_type
Line 71: Line 68:
     email_reminder(mail_worker.find_participant_emails, deadline_text) unless mail_worker.find_participant_emails.empty?
     email_reminder(mail_worker.find_participant_emails, deadline_text) unless mail_worker.find_participant_emails.empty?
   end
   end
 
  ####
   def email_reminder(emails, deadline_type)
   def email_reminder(emails, deadline_type)
     assignment = Assignment.find(self.parent_id)
     assignment = Assignment.find(self.parent_id)
Line 77: Line 74:
     body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}. \
     body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}. \
     Deadline is #{self.due_at}.If you have already done the  #{deadline_type}, Please ignore this mail."
     Deadline is #{self.due_at}.If you have already done the  #{deadline_type}, Please ignore this mail."
     emails.each do |mail|
     emails.each do |mail|
       Rails.logger.info mail
       Rails.logger.info mail
     end
     end
     Mailer.delayed_message(bcc: emails, subject: subject, body: body).deliver_now
     Mailer.delayed_message(bcc: emails, subject: subject, body: body).deliver_now
   end
   end


Line 90: Line 84:
     hours_before_deadline = self.threshold.hours
     hours_before_deadline = self.threshold.hours
     result = (self.due_at.in_time_zone - hours_before_deadline).to_dateti
     result = (self.due_at.in_time_zone - hours_before_deadline).to_dateti


==Automated Testing using RSPEC==
==Automated Testing using RSPEC==
Line 98: Line 89:
We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the mail is enqueued upon the firing of the reminder method.
We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the mail is enqueued upon the firing of the reminder method.


We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the call for reminder method is enqueued upon the firing of the start_reminder method, with the proper scheduled execution time.
We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the call for reminder method is enqueued upon the firing of the '''start_reminder''' method, with the proper scheduled execution time.


      
      
NOTE: All the reminder mails except the ones for the reviewer are sent to expertiza.development@gmail.com ,as this is already set in the development environment.
'''NOTE''': All the reminder mails except the ones for the reviewer are sent to '''''expertiza.development@gmail.com''''' ,as this is already set in the development environment.


==Steps to verify Functionality==
==Steps to verify Functionality==


*Test Email
*Test Email
  Email: [expertiza_test123@outlook.com](mailto:expertiza_test123@outlook.com)
  Email: expertiza_test123@outlook.com
  Password: password98@
  Password: password98@


Line 130: Line 121:
   [[File:create_assignment.png|700px]]
   [[File:create_assignment.png|700px]]


Assign a valid due date and reminder hours
Assign a valid due date and reminder hours. Valid means that the due data minus reminder hour should be a time that is later than the current time. For example, if you set due date to 10:00pm on 10/25/2021 and set reminder hours to 8 hours, then you won't get the email if current date time has passed 2:00pm on 10/25/2021.


   [[File:new_date.png|700px]]
   [[File:new_date.png|700px]]
Line 139: Line 130:


Because the participants was added later, so we need to change the due date once more in order to trigger the email notification jobs.
Because the participants was added later, so we need to change the due date once more in order to trigger the email notification jobs.
  [[File:Email.png|700px]]


==Additional Links==
==Additional Links==


*Git pull link: https://github.com/CuiJinku/expertiza/tree/beta
*Git forked repository link: https://github.com/CuiJinku/expertiza/tree/beta
*VCL deployment: http://152.7.98.122:8080/
*VCL deployment: http://152.7.176.117:8080/
*Pull request link: https://github.com/expertiza/expertiza/pull/2099


==References==
==References==

Latest revision as of 02:08, 7 November 2021

This page provides a description of the Expertiza based OSS project.

About Expertiza

Expertiza is an open-source project developed using the Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. The application allows students to submit and peer-review learning objects (articles, code, websites, etc)[1]. Expertiza supports submission across various document types, including the URLs and wiki pages.

Problem Statement

  • When an assignment or review approaches its deadline on Expertiza, students initially should receive deadline reminder emails at a specific time before the deadline that the instructor has preconfigured. Lack of this functionality sometimes results in students missing their assignment submission deadlines and thus losing marks. Students should receive this type of deadline reminder email. So this amendment to the project involves adding an asynchronous deadline reminder mailer to the application.

    Modified Files

    • app/models/due_date.rb
    • test/models/due_date.rb
    • db/migrate/20210319212323_create_delayed_jobs.rb

    Pre-config

    We use delayed jobs library to deal with the delayed email. We need run following command in order to install delayed_job binary executable.

       rails generate delayed_job
    

    Then we need to run

       RAILS_ENV=development bin/delayed_job start
    

    This will start a backend server to deal with the delayed jobs. If we want to stop, just run following.

       RAILS_ENV=development bin/delayed_job stop
    

    Implementation approach

    1) Reminder email sent when assignment or review is approaching deadline: In the due_date.rb file, whenever a new due date is created or an existing due date is updated, the start_reminder method will be fired which will eventually be added to the delayed_job queue. This job will be executed at a preconfigured time before the deadline, where it will fire the method reminder which will be added to the delayed job queue by the handle_asynchronously method of gem delayed_job_active_record. Inside the reminder method, we will fetch three attributes - assignment_id, deadline_type, due_at. These three attributes will be used to decide the deadline type ( submission or review or teammate review ), fetch the participant email for that assignment, fetch the deadline threshold and at the end send the email reminder at a specified threshold time before the deadline which will contain all the details such as assignment names link to assignment and assignment type ( submission or review or teammate review).

    2) Implement code:

     def create_mailer_object
       Mailer.new
     end
     def create_mailworker_object
       MailWorker.new(self.parent_id, self.deadline_type, self.due_at)
     end
    
     # main function to start email reminder
     def start_reminder
       puts when_to_run_reminder
       if self.changed?
         @extra_param = self.parent_id.to_s + "," + self.deadline_type_id.to_s
         # first deleted existed delayed jobs with same parent_id(which is assignment id actually)
         Delayed::Job.where(extra_param: @extra_param).each do |job|
           job.delete
         end
         # add a delayed job to the delayed job queue, the job will run at what when_to_run_reminder return
         run_at_time = when_to_run_reminder
         if run_at_time >= 0.seconds.from_now
           self.delay(run_at: run_at_time, :extra_param => @extra_param).reminder
         end
       end
     end
     ####
     def reminder
       deadline_text = self.deadline_type if %w[submission review].include? self.deadline_type
       deadline_text = "Team Review" if self.deadline_type == 'metareview'
       mail_worker = create_mailworker_object
       email_reminder(mail_worker.find_participant_emails, deadline_text) unless mail_worker.find_participant_emails.empty?
     end
     ####
     def email_reminder(emails, deadline_type)
       assignment = Assignment.find(self.parent_id)
       subject = "Message regarding #{deadline_type} for assignment #{assignment.name}"
       body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}. \
       Deadline is #{self.due_at}.If you have already done the  #{deadline_type}, Please ignore this mail."
       emails.each do |mail|
         Rails.logger.info mail
       end
       Mailer.delayed_message(bcc: emails, subject: subject, body: body).deliver_now
     end
    
     # after duedate - threshold hours, then we can send the reminder email
     def when_to_run_reminder
       hours_before_deadline = self.threshold.hours
       result = (self.due_at.in_time_zone - hours_before_deadline).to_dateti
    

    Automated Testing using RSPEC

    We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the mail is enqueued upon the firing of the reminder method.

    We have used Rspec for testing the delayed_job functionalities. Using the test-driven development (TDD) approach, we have added a Rspec test which checks whether the call for reminder method is enqueued upon the firing of the start_reminder method, with the proper scheduled execution time.


    NOTE: All the reminder mails except the ones for the reviewer are sent to expertiza.development@gmail.com ,as this is already set in the development environment.

    Steps to verify Functionality

    • Test Email
    Email: expertiza_test123@outlook.com
    Password: password98@
    
    • Test Expertiza account
    name/login: Email_Test_ID1
    password: password98@
    

    1. Change the existing assignment's due date First login in as instructor6, and go to Manage → Assignments

     
    

    Then click change edit in the right side menu under **Actions**. Go to Due dates and change the **reminder** and **Due & Time**, and click save.

     
    

    Then you should receive email at expertiza_test123@outlook.com in the appropriate time. For this example,16 hours before 2021/10/25 04:08 (US Eastern time zone), the system shall send a reminder email to expertiza_test123@outlook.com.

    2. Create a new assignment with valid due date Create a new Assignment

     
    

    Assign a valid due date and reminder hours. Valid means that the due data minus reminder hour should be a time that is later than the current time. For example, if you set due date to 10:00pm on 10/25/2021 and set reminder hours to 8 hours, then you won't get the email if current date time has passed 2:00pm on 10/25/2021.

     
    

    Then add the previous user login to it as a participant

     
    

    Because the participants was added later, so we need to change the due date once more in order to trigger the email notification jobs.

     
    


    Additional Links

    References

    1. Expertiza on GitHub
    2. GitHub Project Repository Fork
    3. The live Expertiza website
    4. Rspec Documentation

    Team

    Dong Li
    Liwen Du
    Jinku Cui