CodeIgniter cron endpoints: best practice for daily scheduled execution, date-window processing, and token-gated stage 2

16 hours ago 1
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 members

I 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:

WHERE mb.completion_status = 0 AND mb.benefit_year = :year AND mb.qr_code_token IS NOT NULL AND mb.qr_code_token <> ''

Would appreciate guidance on production-safe scheduling + locking patterns for this type of two-stage pipeline.

Read Entire Article