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.
| Before | CHANNELS=push | After |
|---|---|---|
trigger_job_application_reminder_job_user: ["email"] | append push | ["email", "push"] |
trigger_job_application_reminder_job_user: [] | append push | ["push"] |
| key not present | create with user-type defaults + push | e.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_TYPESis 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
UserNotificationPreferencerow. Or provideUSER_IDS,CSV_PATH, or GCP bucket CSV.
Required arguments
| Argument | Description | Example |
|---|---|---|
PREFERENCE_NAME | Notification preference key (must exist in NotificationReasons.reasons) | trigger_job_application_reminder_job_user |
CHANNELS | Comma-separated channels to add | push or push,in_app |
USER_TYPES | Comma-separated user types to target | Students or Students,Employers |
Valid channels: email, in_app, push.
Valid user types: Students, Employers, Career Services, Admins, Mentors, Prospects.
User list (one of)
| Option | Description |
|---|---|
| (omit) | All users of the specified types with a UserNotificationPreference row (most common). |
USER_IDS | Comma-separated user IDs (e.g. 125 in local dev). |
CSV_PATH | Local CSV with an id column. |
USE_BUCKET_CSV | If true, use GOOGLE_CLOUD_STORAGE_BUCKET and GOOGLE_CLOUD_STORAGE_PATH. |
Optional arguments
| Argument | Default | Description |
|---|---|---|
BATCH_SIZE | 500 | Users per Sidekiq job. |
DRY_RUN | true | If true, logs what would be enqueued. No jobs dispatched. |
Instructions
- Validate on staging first before running in production.
- Notify the on-call channel that you're running a backfill.
- Schedule large backfills (all users) towards the end of the day to reduce DB load during peak hours.
- 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.
- Choose user list: Omit for all users of the specified types, or set
USER_IDS,CSV_PATH, orUSE_BUCKET_CSV. - Dry run first (default): logs batch counts without enqueuing workers.
- 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