ARTICLE AD BOX
I’m working on a CodeIgniter (PHP) app with a 2-stage batch process:
Cron 1 (syncAndPrepareQRTokens)
sync eligible members to member_benefits
generate qr_code_token
Cron 2 (execute)
generate PDF + send email for membersI have a few architecture/ops questions:
App-side code is ready, but auto-run at midnight needs server scheduler (Task Scheduler/crontab).
Is this the correct separation of responsibility (app provides endpoint, infra schedules it)?
For stage 2 scheduling logic, requirement is:
run daily from configured date onward (scheduled_generation_date <= today)
process only current year
process only rows where qr_code_token IS NOT NULL AND qr_code_token <> ''
Is this query pattern reasonable for reliability?
What is the recommended way to prevent overlap (yesterday’s run still in progress)?
DB lock row?
file lock?
scheduler single-instance policy only?
recommended TTL/expiry pattern?
For large batches, any best practices for:
idempotency
retry strategy
avoiding duplicate emails/PDF generation?
Current relevant pseudo-flow:
And in member selection for stage 2, I want:
Would appreciate guidance on production-safe scheduling + locking patterns for this type of two-stage pipeline.
