Skip to main content

Daily Archiving Job


Overview

The auto-archiver keeps the Visual Experience Engine tidy by moving expired scheduled content from published to archived. Scheduled content that is past its schedule end dates is no longer shown to users, so archiving it reflects its true state and keeps lists manageable.


Schedule and Configuration

SettingDefaultDescription
Scheduleevery 24 hoursHow often the job runs (configurable per site)
Timezoneconfig.ianaTimezoneUsed for schedule timing (e.g. America/New_York)
Timeout300 secondsMax execution time
Memory1GiBFunction memory allocation
Concurrency1Only one instance runs at a time

Configuration lives in consumer configs (e.g. configs/bildit.js, configs/belk.js) under bannersAutoArchiver.


What Gets Archived

Scheduled content is archived when all of these are true:

  1. Publishedpublished === true
  2. Has schedulesbanner.schedules is a non-empty array
  3. All schedules expired – Every schedule has endDate < now

If scheduled content has no schedules, or if any schedule still includes the current time, it is not archived.

Schedule Logic

archived = Array.isArray(banner.schedules)
&& banner.schedules.every((schedule) => now > schedule.endDate)

What the Job Does

For each app in the database:

  1. Fetches all published scheduled content
  2. Checks each scheduled content item's schedules array
  3. For scheduled content items where every schedule has expired:
    • Sets publishedfalse
    • Sets archivedtrue
    • Sets autoArchiveTime → current timestamp (for debugging)
  4. Writes updates in chunks of 50 to stay within Firebase write limits

Manual Trigger

An HTTP-triggered version exists in banners-auto-archive.js for manual runs. It uses the same logic as the scheduled job and can be invoked via the banners_auto_archive function when you need to run archiving on demand (e.g. testing or catching up after downtime).


ConceptReference
Schedule structure (startDate, endDate, slot)Scheduled Content Concept
Scheduled content states (live, scheduled, expired, archived)Scheduled Content Concept
Hooks that run when scheduled content is archivedWebhooks

Implementation

  • Scheduled function: apps/bildit-cms/functions/utility-functions/schedule-functions.jsbannersAutoArchiver
  • HTTP trigger: apps/bildit-cms/functions/utility-functions/banners-auto-archive.js