Skip to content

Backend: Add campaign auto-deactivation job when endDate passes #339

@CelestinaBeing

Description

@CelestinaBeing

Summary

Campaigns with an endDate remain marked active: true in the DB forever after their end date passes — unless an operator manually calls PUT /api/v1/campaigns/:id to deactivate them. An automated background job should deactivate expired campaigns and optionally call the on-chain set_active(false) if a contract is linked.

Problem

In backend/src/index.js, the jobRunner only runs rpc_health_poll. There is no job that checks for expired campaigns.

Acceptance Criteria

  • Add campaign_expiry_check job to jobRunner that runs every 5 minutes (configurable via EXPIRY_CHECK_INTERVAL_MS)
  • Job queries: SELECT * FROM campaigns WHERE active = 1 AND endDate IS NOT NULL AND endDate < NOW()
  • For each expired campaign: set active = false in DB, write an audit log entry with actor system:expiry-job
  • If campaignContractId is set and the backend has an admin key configured (STELLAR_ADMIN_KEY env): build and submit set_active(false) transaction to the campaign contract
  • Emit campaign.deactivated webhook event (when webhooks from issue Backend: Add webhook/notification system for campaign events #287 are available)
  • Add unit tests: campaigns past endDate are deactivated, campaigns before endDate are untouched, campaigns without endDate are untouched
  • Log all auto-deactivations at INFO level

References

  • backend/src/jobs/jobRunner.js
  • backend/src/index.js — job registration

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions