Skip to main content

Backfill Notification Preference

What it does

Adds one or more channels (e.g. push, in_app) to a notification preference for users — without removing channels they already have. Work is delegated to a Sidekiq worker (BackfillNotificationPreferenceWorker) so the rake task finishes quickly and batches run in parallel.

BeforeCHANNELS=pushAfter
trigger_job_application_reminder_job_user: ["email"]append push["email", "push"]
trigger_job_application_reminder_job_user: []append push["push"]
key not presentcreate with user-type defaults + pushe.g. ["email", "in_app", "push"]

The rake task validates PREFERENCE_NAME against Notifications::NotificationReasons.reasons, CHANNELS against valid types, and USER_TYPES against known user types before enqueuing any jobs.

Behavior

  • Appends, never removes: Existing channels on the preference are preserved. Only missing channels are added.
  • Key missing: Created with the user's default channels (from DefaultUserTypesForNotification) merged with the requested channels. If the notification has no defaults for a user type (i.e. the notification doesn't apply to that type), the key is skipped — it won't be created.
  • User type filtering: USER_TYPES is required. Limits processing to the specified user types and filters at the query level so only matching users are batched and enqueued.
  • Sidekiq workers: Rake task validates inputs, resolves user IDs, then enqueues batches to BackfillNotificationPreferenceWorker. Each worker processes one batch using atomic SQL (jsonb_set).
  • User list: Omit for all users of the specified types with a UserNotificationPreference row. Or provide USER_IDS, CSV_PATH, or GCP bucket CSV.

Required arguments

ArgumentDescriptionExample
PREFERENCE_NAMENotification preference key (must exist in NotificationReasons.reasons)trigger_job_application_reminder_job_user
CHANNELSComma-separated channels to addpush or push,in_app
USER_TYPESComma-separated user types to targetStudents or Students,Employers

Valid channels: email, in_app, push. Valid user types: Students, Employers, Career Services, Admins, Mentors, Prospects.

User list (one of)

OptionDescription
(omit)All users of the specified types with a UserNotificationPreference row (most common).
USER_IDSComma-separated user IDs (e.g. 125 in local dev).
CSV_PATHLocal CSV with an id column.
USE_BUCKET_CSVIf true, use GOOGLE_CLOUD_STORAGE_BUCKET and GOOGLE_CLOUD_STORAGE_PATH.

Optional arguments

ArgumentDefaultDescription
BATCH_SIZE500Users per Sidekiq job.
DRY_RUNtrueIf true, logs what would be enqueued. No jobs dispatched.

Instructions

  1. Validate on staging first before running in production.
  2. Notify the on-call channel that you're running a backfill.
  3. Schedule large backfills (all users) towards the end of the day to reduce DB load during peak hours.
  4. Deployer pod size: For large CSVs (500K+ rows), use size 2 (1core, 2Gi) or higher. Size 1 (500Mi) will run out of memory and the pod will be killed silently.
  5. Choose user list: Omit for all users of the specified types, or set USER_IDS, CSV_PATH, or USE_BUCKET_CSV.
  6. Dry run first (default): logs batch counts without enqueuing workers.
  7. Apply: run again with DRY_RUN=false.

Examples:

# All Students (dry run, then apply)
PREFERENCE_NAME=trigger_job_application_reminder_job_user CHANNELS=push USER_TYPES=Students bundle exec rake backfill_notification_preference
PREFERENCE_NAME=trigger_job_application_reminder_job_user CHANNELS=push USER_TYPES=Students DRY_RUN=false bundle exec rake backfill_notification_preference

# Specific user IDs
PREFERENCE_NAME=trigger_job_application_reminder_job_user CHANNELS=push,in_app USER_TYPES=Students USER_IDS=125 bundle exec rake backfill_notification_preference

# Local CSV
PREFERENCE_NAME=trigger_job_application_reminder_job_user CHANNELS=push USER_TYPES=Students CSV_PATH=tmp/user_ids.csv DRY_RUN=false bundle exec rake backfill_notification_preference