Skip to main content

Bi-weekly Usage System

Overview

Sensyze Dataflow uses a bi-weekly (14-day) usage cycle for pipeline execution minutes.

Credit Model

  • Balance: Starts at 120 minutes
  • Diminishes with each pipeline run (not accumulative)
  • Lock: When balance reaches 0, user gets locked for 14 days

Tracking

  • Time measured by: Temporal execution engine (seconds → minutes)
  • Pre-Run Check: API blocks pipeline submission if user is locked (HTTP 429)

Database Tables

profiles

Stores user balance and lock status:

  • balance: Remaining minutes
  • locked: Boolean lock status
  • lock_expires_at: When lock is lifted
  • last_usage_date: Start of current cycle

pipeline_usage

Detailed logs of each pipeline run:

  • user_id: Owner of the pipeline
  • run_id: Unique run identifier
  • duration_seconds: Actual execution time
  • started_at: When pipeline started

ai_usage

AI operation tracking:

  • user_id: Owner
  • operation_type: Type of AI operation
  • week_start: Start of current week

Database Functions

check_and_reset_weekly_usage()

  • Called at login and before each run
  • Resets balance if 14 days have passed since last usage
  • Removes locks if lock period has expired

check_and_unlock()

  • Auto-unlocks user after 14-day lock period
  • Resets balance to 120 minutes

Frontend Display

The /accounts page shows:

  • Bi-weekly Balance with visual progress bar (120 → 0)
  • Current usage in minutes
  • Days remaining in cycle
  • Lock status and unlock date

Example Queries

-- Check user balance
SELECT balance, locked, lock_expires_at
FROM profiles
WHERE id = 'user-uuid';

-- Recent pipeline usage
SELECT run_id, duration_seconds, started_at
FROM pipeline_usage
WHERE user_id = 'user-uuid'
ORDER BY started_at DESC
LIMIT 10;