Skip to content

feat: Implement payroll scheduler backend wiring - #88

Merged
Wilfred007 merged 1 commit into
Protocol-Guild:mainfrom
meshackyaro:payroll-scheduler-backend-wiring
Mar 5, 2026
Merged

feat: Implement payroll scheduler backend wiring#88
Wilfred007 merged 1 commit into
Protocol-Guild:mainfrom
meshackyaro:payroll-scheduler-backend-wiring

Conversation

@meshackyaro

@meshackyaro meshackyaro commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements the backend infrastructure for automated payroll scheduling, connecting the frontend PayrollScheduler components to a persistent database and cron-based execution system.

Changes

Database Layer

  • Added schedules table migration with frequency, time, payment config, and execution tracking
  • Added execution_history table migration for audit logging
  • Created verification scripts for schema validation

Service Layer

  • ScheduleService: CRUD operations for schedules with next run calculation

    • calculateNextRun(): Handles once, weekly, biweekly, monthly frequencies
    • createSchedule(): Validates and persists schedule configurations
    • getActiveSchedules(): Retrieves schedules with pagination
    • cancelSchedule(): Cancels pending schedules with authorization checks
    • updateAfterExecution(): Updates schedule state after execution
  • ScheduleExecutor: Cron-based automated payment execution

    • processDueSchedules(): Queries and processes due schedules every minute
    • executeSchedule(): Builds and submits Stellar bulk payment transactions
    • recordExecution(): Logs execution results to execution_history
    • initialize(): Sets up cron job with graceful shutdown

API Layer

  • POST /api/schedules: Create new payroll schedule
  • GET /api/schedules: List active schedules with pagination
  • DELETE /api/schedules/:id: Cancel pending schedule
  • Zod validation schemas for request validation
  • Comprehensive error handling with structured error responses

Integration

  • Wired ScheduleExecutor into server startup
  • Added graceful shutdown handling for cron job
  • Integrated with existing authentication and authorization middleware
  • Connected to Stellar blockchain via StellarService

Error Handling

  • Request validation with Zod schemas
  • Database transaction safety with rollback
  • Stellar error parsing for meaningful error messages
  • Isolated execution (one failure doesn't block others)

Testing

  • Unit tests for all service methods
  • Manual test scripts for verification
  • Comprehensive validation test coverage

Documentation

  • Migration verification guide
  • Schedule executor implementation guide
  • Database setup instructions

Closes #82

@Wilfred007

Copy link
Copy Markdown
Contributor

Hi @meshackyaro kindly resolve conflicts

- Add database migrations for schedules and execution_history tables
- Implement ScheduleService with CRUD operations and next run calculation
- Create REST API endpoints (POST/GET/DELETE /api/schedules)
- Implement ScheduleExecutor with cron job for automated payment execution
- Integrate with Stellar blockchain for bulk payments
- Add comprehensive error handling and validation
- Wire cron executor into server startup with graceful shutdown

Closes #81
@meshackyaro
meshackyaro force-pushed the payroll-scheduler-backend-wiring branch from 8b1aac7 to cd09494 Compare March 3, 2026 10:26
@meshackyaro

Copy link
Copy Markdown
Contributor Author

conflicts resolved please check

@Wilfred007
Wilfred007 merged commit 5765326 into Protocol-Guild:main Mar 5, 2026
1 check passed
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.

#081: Payroll Scheduler Backend Wiring

2 participants