File size: 1,565 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Python interval scheduler
Implement a Python interval scheduler from the behavior documented in `original_go/cron.go`. Keep that file as the source specification. Cron expression parsing is out of scope. Run offline.
## API and deliverables
Export `CronScheduler` and `IntervalSchedule` from the `pycron` package. `IntervalSchedule(seconds)` stores a positive finite interval. `CronScheduler.add_interval_job(seconds, callback)` registers a recurring job. Reject zero, negative, NaN and infinite durations immediately with `ValueError` or `TypeError`.
Jobs do not run until `start()`. Each has its own interval and first executes no sooner than one full interval after starting, allowing normal scheduling delay. Calling `start()` again while running must not duplicate callbacks. `stop()` cancels pending executions and prevents further callbacks; a later `start()` resumes the registered schedule.
Provide a runnable `example/example.py` that demonstrates a scheduled callback and prints its result. Write `README.md` explaining features, usage and the scope of the Go behavior specification.
## Acceptance Checklist
- The package imports both classes; the example runs and produces demonstration output, and the README explains usage.
- Jobs stay dormant before starting, execute repeatedly at independent intervals and never execute early. Repeated starts do not produce duplicate ticking.
- Stop prevents future callbacks, including a pending first callback; restarting resumes execution.
- Both public interval entry points reject invalid durations.
|