Skip to content

Overview

Summary of Jobs

The application includes a variety of background jobs to handle different tasks asynchronously. These jobs are managed using Sidekiq, a background processing library for Ruby. Here is a brief summary of the jobs involved:

  • ApplicationJob: The base class for all jobs, providing common configurations and settings.
  • BulkDownloadJob: Handles bulk download operations.
  • CasestudyApprovalNotifyJob: Sends notifications for case study approvals.
  • CasestudyPendingApprovalNotifyJob: Sends notifications for case studies pending approval.
  • CasestudyRejectionNotifyJob: Sends notifications for case study rejections.
  • ClassroomReportApprovalNotifyJob: Sends notifications for classroom report approvals.
  • ClassroomReportPendingApprovalNotifyJob: Sends notifications for classroom reports pending approval.
  • ClassroomReportRejectionNotifyJob: Sends notifications for classroom report rejections.
  • GenericRecordJob: A versatile job that can call arbitrary methods on records.
  • IepApprovalNotifyJob: Sends notifications for IEP approvals.
  • IepOffboardingAssessmentGenerationJob: Generates assessments for IEP offboarding.
  • IepOnboardingAssessmentGenerationJob: Generates assessments for IEP onboarding.
  • IepOnboardingHistoricalAssessmentGenerationJob: Generates historical assessments for IEP onboarding.

Sidekiq Integration

The application uses Sidekiq for background job processing. Sidekiq is a powerful and efficient background processing library for Ruby that uses threads to handle many jobs at the same time in the same process. Each job class includes configurations for Sidekiq, such as queue settings and retry options.

GenericRecordJob

The GenericRecordJob is a versatile job that simplifies calling arbitrary methods on records in the background. It inherits from ApplicationJob and is configured to use the :low queue with no retries.

Code Example

class GenericRecordJob < ApplicationJob
  queue_as :low
  sidekiq_options retry: false, queue: :low

  def perform(record_classname, record_id, method_name, method_args = [])
    record_class = record_classname.classify.safe_constantize
    record = record_class.unscoped.find_by(id: record_id)
    if record.present?
      if record.respond_to?(:school) && record.school.present?
        ActsAsTenant.with_tenant(record.school) do
          record.send(method_name.to_sym, *method_args)
        end
      else
        record.send(method_name.to_sym, *method_args)
      end
    end
  end
end

How It Works

The GenericRecordJob takes four parameters:

  • record_classname: The name of the record class.
  • record_id: The ID of the record.
  • method_name: The name of the method to be called on the record.
  • method_args: An array of arguments to be passed to the method.

When the job is performed, it:

  1. Converts the record_classname to a constant.
  2. Finds the record by its ID.
  3. Checks if the record is present and, if it belongs to a school, sets the tenant context using ActsAsTenant.
  4. Calls the specified method on the record with the provided arguments.

Benefits

The GenericRecordJob simplifies the process of calling arbitrary methods on records in the background. It provides a flexible and reusable way to handle various tasks without the need to create separate job classes for each method call. This reduces code duplication and makes it easier to manage background processing in the application.