Skip to content

feat: daily uptime points system with cron automation#497

Open
albert-mr wants to merge 6 commits intodevfrom
daily-uptime-points-fix
Open

feat: daily uptime points system with cron automation#497
albert-mr wants to merge 6 commits intodevfrom
daily-uptime-points-fix

Conversation

@albert-mr
Copy link
Copy Markdown
Collaborator

@albert-mr albert-mr commented Mar 27, 2026

Summary

  • Rewrite add_daily_uptime management command with date range backfill support, bulk operations, and atomic transactions
  • Add POST /api/v1/validators/wallets/daily-uptime/ endpoint (IsCronToken-protected) for cron automation
  • Add GitHub Actions workflow running daily at 00:30 UTC
  • Add data migration (0041) to create "Uptime" ContributionType and its multiplier
  • Fix migration 0037 crash in test environments when seed users don't exist

Deployment Instructions

1. Run database migration (required)

After deploying, run the migration to create the "Uptime" ContributionType and its 2.0x multiplier:

python manage.py migrate contributions

Migration 0041_create_uptime_contribution_type will automatically create:

  • ContributionType: name="Uptime", slug="uptime", category=validator
  • GlobalLeaderboardMultiplier: 2.0x multiplier for the Uptime type

2. Verify GitHub Secrets (in cron-job environment)

  • CRON_SYNC_TOKEN — same token used by the existing sync-validators workflow
  • API_BASE_URL — production API base URL (e.g., https://api.points.genlayer.com)

3. Verify the workflow

After merge, manually trigger via GitHub Actions -> "Daily Uptime Points" -> "Run workflow":

# Or test locally:
python manage.py add_daily_uptime --dry-run --verbose
python manage.py add_daily_uptime --verbose  # actual run

Backfilling historical data (if needed)

python manage.py add_daily_uptime --start-date 2026-01-01 --end-date 2026-03-26 --verbose
# Add --force to use multiplier=1.0 if no multiplier exists for older dates
python manage.py add_daily_uptime --start-date 2026-01-01 --end-date 2026-03-26 --force --verbose

Test Coverage

All new code paths have test coverage (16 tests, 100% path coverage).

Pre-Landing Review

No issues found.

Test plan

  • All 16 Django tests pass (contributions.tests.test_add_daily_uptime)
  • After deploy: run python manage.py migrate contributions
  • After merge: manually trigger "Daily Uptime Points" workflow in GitHub Actions
  • Verify CRON_SYNC_TOKEN and API_BASE_URL secrets are configured in cron-job environment

albert-mr and others added 6 commits March 27, 2026 11:06
The seed_featured_content migration (0037) assumed specific users always
exist, causing crashes in test environments. Added try/except to skip
seeding gracefully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…perations

Major refactor of the add_daily_uptime management command:
- Add --date, --start-date, --end-date params for backfilling historical data
- Refactor from per-user DB saves to bulk_create with batch processing
- Add snapshot-based activity verification with fallback for recent dates
- Wrap all operations in atomic transaction for data consistency
- Use shared leaderboard helpers (update_user_leaderboard_entries,
  update_referrer_points) instead of manual leaderboard entry management
- Raise CommandError on complete failure to surface to HTTP callers
- Comprehensive test suite (16 tests) covering all command paths

Database migration note: This command requires the "Uptime" ContributionType
to exist. Run the daily uptime workflow after deploying, or manually via:
  python manage.py add_daily_uptime --verbose

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add POST /api/v1/validators/wallets/daily-uptime/ endpoint protected by
IsCronToken authentication. Calls the add_daily_uptime management command
and returns success/failure with output details.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Runs at 00:30 UTC daily, triggers the daily-uptime endpoint with
CRON_SYNC_TOKEN. Supports manual workflow_dispatch for ad-hoc runs.

Setup requirements:
- Set CRON_SYNC_TOKEN secret in the 'cron-job' environment
- Set API_BASE_URL secret pointing to the production API
- The "Uptime" ContributionType must exist in the database
- A GlobalLeaderboardMultiplier for "Uptime" must be active

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add validator endpoints to API summary and add_daily_uptime command
to common commands section.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Creates the "Uptime" ContributionType (slug: uptime, category: validator)
and its initial GlobalLeaderboardMultiplier (2.0x) via RunPython migration.
Required for the add_daily_uptime command to function.

Run after deploy: python manage.py migrate contributions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant