VOOZH about

URL: https://deepwiki.com/hypervel/telescope/2.3.5-schedule-watcher

⇱ Schedule Watcher | hypervel/telescope | DeepWiki


Loading...
Last indexed: 7 February 2026 (146f77)
Menu

Schedule Watcher

The Schedule Watcher monitors scheduled tasks (cron jobs) executed by the Hypervel framework's task scheduler. It captures information about each scheduled task execution, including the command, cron expression, output, and execution status. This watcher provides visibility into automated background tasks that run on a schedule.

For information about monitoring console commands triggered manually, see Command Watcher. For information about monitoring queued jobs, see Additional Watchers.

Purpose and Activation Context

The Schedule Watcher differs from most other watchers in that it only activates when the application is running in scheduler context. It performs an explicit check for the scheduler commands crontab:run or schedule:run in the $_SERVER['argv'] array before registering its event listeners.

Activation Check: $_SERVER['argv'][1] in ['crontab:run', 'schedule:run']

This conditional registration ensures that the watcher only imposes overhead during scheduled task execution, not during normal HTTP requests or other command executions.

Sources:

Architecture and Event Integration

The Schedule Watcher monitors three lifecycle events dispatched by the Hypervel console scheduler:

Event ClassTrigger PointPurpose
Events\ScheduledTaskStartingBefore task execution beginsEnables recording for the task
Events\ScheduledTaskFinishedAfter task completes successfullyRecords task details and output
Events\ScheduledTaskFailedAfter task fails with exceptionRecords task details and failure information

Event Flow Diagram


Sources:

Registration Logic

The Schedule Watcher's registration process is unique among watchers:


The watcher stores both the container instance and the EntriesRepository as instance properties because it needs them later for immediate storage operations, which differs from the deferred storage pattern used by most other watchers.

Sources:

Entry Recording and Data Capture

When a scheduled task completes or fails, the watcher creates an entry with comprehensive task metadata:

Captured Data Fields

FieldSourceDescription
command$task->commandThe console command string (or 'Closure' for callbacks)
description$task->descriptionHuman-readable task description
expression$task->expressionCron expression defining the schedule
timezone$task->timezoneTimezone for schedule evaluation
user$task->userUser context for task execution
output$task->getOutput($app)Captured console output from the task

Command Type Detection

The watcher distinguishes between two types of scheduled tasks:


When the scheduled task is a CallbackEvent (a closure-based task), the command field is set to the string 'Closure' rather than attempting to serialize the callback. For command-based tasks, the actual command string is captured.

Sources:

Immediate Storage Pattern

Unlike most watchers that defer storage to request completion, the Schedule Watcher uses an immediate storage pattern:


This immediate storage is necessary because:

  1. No Request Context: Scheduled tasks don't have the request lifecycle hooks that trigger deferred storage
  2. Isolated Execution: Each task runs independently without a persistent context
  3. Immediate Feedback: Developers need to see task execution results immediately in the Telescope UI

The watcher explicitly calls Telescope::store($this->entriesRepository) after recording each entry, bypassing the normal deferred storage mechanism.

Sources:

Recording State Management

The Schedule Watcher manages recording state across task executions:

State Initialization

During registration, the watcher calls Telescope::startRecording() to enable monitoring for the entire scheduler run. This ensures that any nested operations (database queries, cache operations, etc.) performed by scheduled tasks are also captured by their respective watchers.

Task-Level Recording

When a ScheduledTaskStarting event fires, the watcher calls Telescope::startRecording() again. This resets the recording context for the new task, ensuring each task's operations are properly tracked.

Recording Check

Before recording task completion, the watcher verifies that recording is active:

if (! Telescope::isRecording()) {
 return;
}

This check prevents recording entries when Telescope is paused or disabled.

Sources:

Configuration

The Schedule Watcher is configured in the telescope.php configuration file under the watchers array:


Configuration Options

OptionTypeDefaultDescription
enabledbooltrueEnable or disable scheduled task monitoring

The Schedule Watcher does not support additional configuration options such as ignore lists or size limits because scheduled tasks are typically administrative operations that should always be monitored when the watcher is enabled.

Sources:

Integration with Other System Components

The Schedule Watcher interacts with several framework components:


The watcher depends on:

  • Hypervel Console Events: Provides the three lifecycle events
  • ContainerInterface: Resolves dependencies and passes to task for output generation
  • EventDispatcherInterface: Event listener registration
  • EntriesRepository: Direct storage access
  • CallbackEvent: Type detection for closure-based tasks

Sources:

Output Capture

The Schedule Watcher captures console output from scheduled tasks by calling $task->getOutput($this->app). This method retrieves the buffered console output produced during task execution, providing visibility into what the task printed, logged, or displayed.

The container instance ($this->app) is passed to the output retrieval method, allowing the task to access application services if needed during output generation.

Sources:

Entry Type Classification

Entries created by the Schedule Watcher are classified with the type 'schedule', which allows them to be filtered and queried in the Telescope UI. The Telescope::recordScheduledCommand() method internally creates an IncomingEntry with this type designation.

This classification enables developers to:

  • Filter entries to show only scheduled task executions
  • Analyze scheduled task performance patterns
  • Debug issues specific to automated background processes

Sources: