Background processing and notifications
Background processing lets iTop run work outside the user request. A host scheduler starts the cron entry point, which coordinates timed processes and database-backed asynchronous tasks. The same flow supports email delivery, in-app newsroom messages, event records, and status views. See Integrations and automation for the wider automation model.
Processing model
The processing model separates work that repeats on a clock from work that waits in a durable task queue. This keeps long or delayed work out of the user request while giving operators a common view of schedule, progress, and failure.
Cron coordination
The cron runner is the service entry point for background work. A system scheduler calls it at a regular interval. The runner authenticates an administrator, takes a single cron lock, stops during read-only or maintenance mode, and processes due work until its time limit. It can also return task status without running tasks. The Windows wrapper shows the intended pattern for a host scheduler and log file.
flowchart LR
Scheduler[Host scheduler] --> Cron[cron runner]
Cron --> Lock[Single cron lock]
Lock --> Due[Due background tasks]
Due --> Process[Process work]
Process --> Status[Run dates and duration status]
Cron --> Report[Status-only report]
References: webservices/cron.php• L187-297 webservices/cron.php• L321-345 webservices/cron.php• L463-531 webservices/cron.cmd• L3-23
Timed process types
A timed process declares one unit of work and a way to calculate its next run. A periodic process runs again after a fixed interval. A scheduled process runs at selected calendar times. The scheduler discovers these process types and creates or updates their task records, so an extension can add background work without changing the cron loop.
The scheduler records the planned time before each run and advances it after the run. Scheduled processes can be disabled through their schedule settings. Invalid schedule settings stop that process from being planned correctly and must be treated as an operational configuration error.
References: core/backgroundprocess.inc.php• L21-63 core/backgroundprocess.inc.php• L81-106 core/backgroundprocess.inc.php• L171-240 webservices/cron.php• L362-431
Asynchronous task queue
An asynchronous task is a database record that represents work to complete later. The ExecAsyncTask background process checks for planned tasks and handles them in creation order until the cron time limit. A task claims ownership before it runs, which prevents a second worker from processing the same record at the same time.
Tasks report planned, running, idle, or error state. A failed task can record its error and wait for a later retry. Retry policy can set a delay, a retry count, and exponential delay. A task that completes is removed from the queue. A task that reaches its retry limit stays in an error state and can notify the owning feature through its definitive-failure hook.
flowchart TD
Create[Create task record] --> Planned[Planned]
Planned --> Claim[Claim task]
Claim -->|Already owned| Wait[Leave for current owner]
Claim -->|Owned| Run[Run task]
Run -->|Success| Remove[Remove task]
Run -->|Retry remains| Retry[Plan next attempt]
Retry --> Planned
Run -->|No retry remains| Error[Error state and failure notice]
References: core/asynctask.class.inc.php• L28-55 core/asynctask.class.inc.php• L63-97 core/asynctask.class.inc.php• L119-162 core/asynctask.class.inc.php• L232-317
Event and notification flow
Triggers connect a system event to one or more actions. An event can be an object create, update, delete, state change, mention, portal update, threshold, or another supported application signal. A trigger checks its context and object scope before it runs linked active actions in their configured order.
Trigger activation
The trigger is the decision point for automation. It can limit activation by application context, target class, an object query, or a changed attribute. The linked action list then turns the accepted event into an effect such as a notification or a web request. This separates the condition from the delivery channel and lets one trigger drive more than one action.
References: core/trigger.class.inc.php• L23-69 core/trigger.class.inc.php• L71-143 core/trigger.class.inc.php• L164-268 core/trigger.class.inc.php• L597-647
Notification subscriptions
Notification subscriptions control whether a contact receives a notification for a trigger and action pair. A contact is normally treated as subscribed until an explicit choice says otherwise. A trigger can also require delivery through every channel, which overrides an unsubscribe for that trigger.
Recipient selection applies the subscription choice while an action resolves its recipient set. This means a notification action can keep its recipient rule while the notification service applies the contact’s channel preference.
References: sources/…/NotificationsService.php• L49-86 sources/…/NotificationsService.php• L88-118 sources/…/NotificationsRepository.php• L152-221 core/email.class.inc.php• L477-538
Email delivery
Email notifications build a message from the action and the triggering object. They resolve recipients from object queries, apply the message language and placeholders, then send through the configured mail service. An action can use synchronous delivery or place the message in the asynchronous queue. The per-action choice can follow the global email setting or override it.
The configured mail service selects a delivery transport. The PHP mail transport passes the message to the server’s PHP mail facility and reports a transport error when that facility rejects the send. When asynchronous email is selected, iTop stores enough message data to send it later and links the queued task to its event record. The event record then reports pending, sent, or failed status. Test actions redirect delivery to the configured test recipient and avoid copying test mail to carbon-copy or blind-copy recipients.
References: sources/…/SymfonyPHPMailTransport.php• L9-12 sources/…/SymfonyPHPMailTransport.php• L73-99 sources/…/EmailSymfony.php• L223-250 core/action.class.inc.php• L42-107 core/action.class.inc.php• L246-270 core/action.class.inc.php• L278-339 core/action.class.inc.php• L347-451 core/action.class.inc.php• L547-657 core/action.class.inc.php• L898-905 core/asynctask.class.inc.php• L333-417
Newsroom delivery
Newsroom delivery creates an in-app message for each selected contact. The message carries a title, body, priority, link, date, and icon. A queued newsroom task creates these contact-specific messages after the trigger action has completed, so the action does not need to wait for each recipient’s inbox record.
The built-in newsroom provider supplies unread messages to the navigation menu and supports a view-all page and mark-all-as-read action. The provider model also allows other sources to expose their own message feed through the same menu. User preferences control provider visibility and the number of messages shown.
References: core/asynctask.class.inc.php• L420-500 sources/…/EventNotificationNewsroomService.php• L14-75 application/newsroomprovider.class.php• L20-81 sources/…/iTopNewsroomProvider.php• L19-53 sources/…/NewsroomMenuFactory.php• L55-103
Event records
Event records provide the audit link between a trigger, an action, the affected object, and the delivery result. Email events can keep message details and recipient data. Newsroom events belong to one contact and retain the message link and read state. These records let the product show what happened without requiring the original user request to remain open.
References: core/event.class.inc.php• L23-48 core/event.class.inc.php• L117-186 core/asynctask.class.inc.php• L217-317 core/action.class.inc.php• L216-244
Newsroom user experience
The newsroom is the in-app channel for messages that users can read later. It fetches only unread messages for the current contact, marks messages as read when the user opens them or uses a bulk action, and keeps access tied to the intended recipient.
Message access
The navigation menu polls the built-in provider for unread messages. A user can open one message to follow its target link, view all messages, mark messages read or unread, or delete them. The controller checks the contact attached to the message before it returns message data or its icon.
References: sources/…/iTopNewsroomController.php• L528-570 sources/…/iTopNewsroomController.php• L582-631 sources/…/iTopNewsroomController.php• L636-725 sources/…/NotificationsRepository.php• L51-132
Read-message retention
Read newsroom messages are temporary records. A daily background process removes messages that have been read longer than the configured retention period. Unread messages are not selected by this cleanup, so a user can keep an unread message until it is read or deleted.
References: sources/…/EventNotificationNewsroomGC.php• L12-32
Operational status
Operational status comes from the same records that coordinate work. Background task records show whether a process is active, paused, removed, or running, along with planned and recent run times and duration measures. Event records show the result of notification actions. Logs capture failures that cannot be represented safely in the event record.
Task status reporting
The cron status view gives an operator a compact view of each discovered process. It shows task state, the last and next run, the number of runs, and average duration. A missing process class is marked removed during synchronization, which helps distinguish an obsolete task record from a process that is temporarily failing.
References: core/backgroundtask.class.inc.php• L20-27 core/backgroundtask.class.inc.php• L62-91 webservices/cron.php• L321-345 webservices/cron.php• L374-431
Notification status reporting
Notification actions create or update an event record around delivery. The record can show that delivery is pending before an asynchronous task runs, then show the task result or an error. Action history uses these records to show recent executions for a configured period.
References: core/action.class.inc.php• L192-244 core/action.class.inc.php• L547-597 core/asynctask.class.inc.php• L237-310
Related pages
- Integrations and automation — parent view of triggers, actions, and external integrations.
- Web service APIs — request and response flows that can create events or run actions.
- Data exchange and synchronization — scheduled data movement and its relationship to background work.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the cron discovery contract aligned with every process type. A process that is no longer discoverable can leave a stale task record that is marked removed.
- Keep asynchronous task status, retry timing, and event message updates aligned. A change in one state path can make the operator view disagree with the queue.
- Keep the event link intact when adding an asynchronous notification channel. The link is what connects delayed delivery to action history.
- Keep recipient subscription checks consistent with both the trigger policy and the action channel. A new channel must not silently ignore an explicit unsubscribe or a force-all policy.
- Keep the selected email transport’s failure result aligned with event and action status. A server-level send failure must not appear as successful notification delivery.
- Keep newsroom cleanup rules aligned with read-state changes. Changing when
read_dateis set changes when messages become eligible for deletion.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The host scheduler does not call the cron runner | Timed processes and asynchronous tasks remain planned and notifications do not leave the queue. | Check the cron status output and the scheduler log. |
| A second cron run starts while one run holds the cron lock | The second run exits without processing work. | Keep one scheduler entry and inspect the lock message before treating the queue as stalled. |
| A process class is removed or cannot be discovered | Its task record is marked removed and no further runs occur. | Check process discovery after module changes and review removed task records. |
| An asynchronous task exhausts its retries | The task stays in error and its linked notification is not delivered. | Review the stored error and retry settings. Provide a definitive-failure notification when the feature needs one. |
| The PHP mail facility rejects a message or the server mail setup is not ready | Synchronous delivery reports an email error and asynchronous delivery records a failed task or event result. | Check the selected transport and the server mail configuration. |
| An email recipient query is invalid or returns no usable address | The event reports that the notification was not sent or had no recipient. | Validate recipient queries and contact email data before enabling the action. |
| A newsroom message is addressed to a different contact | The message and its icon are not returned to the current user. | Keep contact ownership checks in all message read, view, and download paths. |
| Read-message retention is too short | Users can lose old read newsroom messages sooner than expected. | Set retention with the product’s message review needs in mind. |
Key files
| File | Why to read it |
|---|---|
| webservices/cron.php | Primary coordinator for timed processes, asynchronous work, locking, maintenance checks, and status output. |
| core/backgroundprocess.inc.php | Defines the shared model for periodic and calendar-based background processes. |
| core/asynctask.class.inc.php | Defines queued work, ownership, retry behavior, and the built-in email and newsroom task types. |
| core/backgroundtask.class.inc.php | Defines the durable run state and timing measures shown to operators. |
| core/trigger.class.inc.php | Explains how events are scoped and mapped to ordered actions. |
| core/action.class.inc.php | Defines action status, asynchronous choice, notification actions, and action execution history. |
| core/email.class.inc.php | Defines the mail abstraction and delivery result states. |
| sources/…/EmailSymfony.php | Selects the configured email transport and maps send outcomes to email status. |
| sources/…/SymfonyPHPMailTransport.php | Shows the server-mail transport used for PHP mail delivery and its send-failure boundary. |
| core/event.class.inc.php | Defines event records used for audit and notification status. |
| sources/…/NotificationsService.php | Defines subscription decisions for notification recipients. |
| sources/…/NotificationsRepository.php | Defines the main notification and subscription queries. |
| sources/…/EventNotificationNewsroomService.php | Builds contact-specific newsroom events and protects icon access. |
| sources/…/iTopNewsroomController.php | Connects the newsroom menu and view-all page to unread, read, and delete operations. |
| sources/…/EventNotificationNewsroomGC.php | Removes read newsroom messages after retention. |
| sources/…/iTopNewsroomProvider.php | Exposes the built-in newsroom feed to the shared provider menu. |