Skip to content

Create recurring tasks on a schedule

Use a cron workflow to create real task records when each occurrence needs its own status or owner. This minimal daily task has a name; extend its schema and form for your business fields.

Copy the Bakery definitions into the system directory, inspect php bakery plan <system>, then apply them in a disposable preview with php bakery apply <system>. A client must already exist. The complete module/workflow definitions below follow verified element and frequency syntax; this assembled scenario has not been executed here. Put them in daily-tasks.bake.json.

[
{
"resource_module": "daily_tasks",
"resource": {
"identifier": "daily_tasks",
"title": "name",
"fields": [
{
"identifier": "name",
"type": "text"
}
]
}
},
{
"resource_workflow": "create_daily_task",
"resource": {
"identifier": "create_daily_task",
"title": "Create daily task",
"active": true,
"async": false,
"entry": "daily",
"elements": [
{
"name": "daily",
"type": "event/cron",
"options": {
"client": null,
"frequency": [
[
{
"schedule": "dailyAt",
"parameters": [
"08:00"
]
}
]
]
},
"to": {
"default": {
"newTask": [
"default"
]
}
}
},
{
"name": "newTask",
"type": "source/new",
"options": {
"module": "daily_tasks"
},
"to": {
"default": {
"setName": [
"default"
]
}
}
},
{
"name": "setName",
"type": "op/set",
"options": {
"recipes": {
"name": "\"Daily check\""
}
},
"to": {
"default": {
"save": [
"default"
]
}
}
},
{
"name": "save",
"type": "action/save",
"options": {
"triggerEvents": false
}
}
],
"events": [
{
"identifier": "daily",
"type": "cron",
"frequency": [
[
{
"schedule": "dailyAt",
"parameters": [
"08:00"
]
}
]
]
}
]
}
}
]

The registered cron event supplies the client context. source/new creates an unsaved record, op/set supplies the name and action/save persists it. Production requires the Brezel scheduler. Each dispatch creates another record: if retries or parallel schedules must not duplicate an occurrence, add a period key and a server-side uniqueness strategy before deployment.

Save this unexecuted test as tests/daily-task.test.workflow.json and run php bakery system test-run <system> in the preview. It dispatches the cron entry rather than waiting for the scheduler clock.

{
"identifier": "daily_task_created",
"workflow": "create_daily_task",
"trigger": {
"type": "dispatch_sync",
"entry": "daily"
},
"assertions": [
{
"type": "count_equals",
"module": "daily_tasks",
"where": {
"name": "Daily check"
},
"value": 1
}
]
}
  • Recommended for per-template recurrence: cron selects due templates and creates occurrences. Building blocks are supported; the full template-copy pattern is unverified.
  • Recommended for calendar display only: calendar recurrence/recurrence_field. It does not create task records; verify the complete recurrence configuration in your target UI.
  • Recommended for client-side suggestions or display: rrule(); it does not persist occurrences by itself.
  • Recommended for agent work only: AgentSchedules. Not recommended for deterministic business task creation.

New record · Cron · Calendar options · Workflow tests · Assertions