Skip to content

Add TaskMetadata for instantiation-free task introspection#3

Open
jamisonbryant wants to merge 2 commits intocake5from
fix/task-metadata-introspection
Open

Add TaskMetadata for instantiation-free task introspection#3
jamisonbryant wants to merge 2 commits intocake5from
fix/task-metadata-introspection

Conversation

@jamisonbryant
Copy link
Copy Markdown
Owner

Summary

Fixes the CI failures in dereuromark#470 where tasks with required DI constructor params cause ArgumentCountError when Config::taskConfig(), QueueController::index(), and QueueHelper try to read metadata via new $className().

  • Add TaskMetadata class that reads property defaults (timeout, retries, rate, costs, unique) via ReflectionProperty::getDefaultValue() and description() via newInstanceWithoutConstructor() — no constructor invocation needed
  • Update Config::taskConfig() and QueueController::index() to use TaskMetadata::fromClass() instead of direct instantiation
  • Use is_subclass_of() for interface checks in QueueController::addJob() to avoid instantiating DI tasks

Test plan

  • TaskMetadataTest — 3 tests covering property defaults, description, and DI constructor tasks
  • Full test suite passes (161 tests, 0 failures)
  • phpcs clean
  • phpstan clean

Read task property defaults (timeout, retries, rate, costs, unique)
and description via reflection instead of instantiating the class.
This supports tasks with required DI constructor parameters where
new $className() would fail with ArgumentCountError.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds instantiation-free task introspection to avoid ArgumentCountError for tasks with required constructor DI params when the system reads task metadata (timeout/retries/rate/costs/unique/description).

Changes:

  • Introduces Queue\Queue\TaskMetadata to read task property defaults via reflection and obtain description() without invoking constructors.
  • Updates Config::taskConfig() and Admin\QueueController::index() to use TaskMetadata::fromClass() instead of new $className().
  • Adds/updates tests and test-app fixtures to cover metadata introspection and DI-constructor tasks.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Queue/TaskMetadata.php New reflection-based metadata reader to avoid task instantiation.
src/Queue/Config.php Switches task config building to read metadata via TaskMetadata.
src/Controller/Admin/QueueController.php Avoids instantiating tasks for descriptions; uses is_subclass_of() for interface checks before instantiation.
tests/TestCase/Queue/TaskMetadataTest.php Adds coverage for property-default reading, description reading, and DI-constructor tasks.
tests/test_app/src/Queue/Task/MetadataTask.php Test fixture task with explicit metadata defaults and description override.
tests/TestCase/Command/InfoCommandTest.php Updates expected task count due to new test task fixture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update Config::taskConfig() and QueueController::index() to use
TaskMetadata::fromClass() instead of new $className() for reading
task properties and descriptions. Also use is_subclass_of() for
interface checks in addJob() to avoid instantiating DI tasks.
@jamisonbryant jamisonbryant force-pushed the fix/task-metadata-introspection branch from c79309d to d20b759 Compare March 31, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants