Schedule and batch work
Use explicit time zones and prepare bounded batches and useful digests. This module has 3 lessons and takes about 1h 50m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.
Start module 15 in the Learning LabCompare aware timestamps
Return due when an offset-aware due timestamp is no later than now, wait when later, and review for invalid or naive timestamps.
Schedules need a time zone. A naive timestamp does not say which local time it represents. Store an offset or UTC and show people the intended local time.
datetime.fromisoformat reads ISO timestamps. This function accepts strings with explicit offsets and compares the instants. Missing offsets or invalid dates return review.
A daily local schedule can interact with daylight-saving changes. Use a named time zone and an explicit policy for skipped or repeated times in a real scheduler.
See it in action
def solve(due, now):
from datetime import datetime
try:
due_time, now_time = datetime.fromisoformat(due), datetime.fromisoformat(now)
if due_time.tzinfo is None or now_time.tzinfo is None:
return "review"
return "due" if due_time <= now_time else "wait"
except (ValueError, TypeError):
return "review"
print(solve("2026-11-02T09:00:00+01:00", "2026-11-02T08:00:00+00:00"))
A daily local schedule can interact with daylight-saving changes. Use a named time zone and an explicit policy for skipped or repeated times in a real scheduler.
Split a queue into batches
Return ordered batches of at most size items, or an empty list for a non-positive or non-integer size.
A batch limits how much work one run handles. Smaller batches can reduce peak memory and simplify recovery, though they may increase overhead.
Use list slices in steps of size. Keep the input order and include a shorter final batch. Reject non-positive or non-integer sizes, including booleans.
Batching does not remove provider rate limits. Limit concurrency and total requests separately.
See it in action
def solve(items, size):
if type(size) is not int or size <= 0:
return []
return [items[index:index + size] for index in range(0, len(items), size)]
print(solve([1,2,3,4,5], 2))
Batching does not remove provider rate limits. Limit concurrency and total requests separately.
Practical: Prepare a daily operations digest
Return counts for done, failed, and review. Count all statuses other than done or failed as review.
A digest should help an owner act. Count completed work, items needing review, and failures. A summary should not hide unknown statuses.
This function counts done and failed exactly. Every other status counts as review. It prepares a local record and does not send a message.
Choose a digest owner and an escalation threshold. A report without a response process can become ignored noise.
Your experiment plan
Use the browser editor or the notebook. All records and AI responses are fictional. No network calls, credentials, or real messages are used.
- Combine an explicit due time, a batch size, and fictional job statuses.
- Run the example and predict its result before changing it.
- Complete the function in Practice and run the checks. Add your own normal, empty, and failure cases.
- Add an unknown status and verify the total still includes every job.
- Save the notebook with your observations and explain one limitation of the simulation.
What to hand in
- A schedule specification and a daily digest with escalation rules.
- A test table with inputs, expected outputs, actual outputs, and one revision.
Reflect on your results
When should the workflow notify immediately instead of waiting for a digest?
The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.
See it in action
def solve(statuses):
result = {"done":0, "review":0, "failed":0}
for status in statuses:
key = status if status in ("done", "failed") else "review"
result[key] += 1
return result
print(solve(["done","pending","failed","unknown","done"]))
Choose a digest owner and an escalation threshold. A report without a response process can become ignored noise.
Free, open and run by a nonprofit.
This page is part of AI Automation, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.