Skip to content

Fix silent no-op in Queue::addJob when task does not queue a job#478

Merged
dereuromark merged 1 commit intomasterfrom
fix-addjob-silent-failure
Apr 22, 2026
Merged

Fix silent no-op in Queue::addJob when task does not queue a job#478
dereuromark merged 1 commit intomasterfrom
fix-addjob-silent-failure

Conversation

@dereuromark
Copy link
Copy Markdown
Owner

@dereuromark dereuromark commented Apr 22, 2026

Problem

The admin UI has a "Trigger Jobs" panel that lets operators add demo jobs via Queue::addJob(). For tasks implementing AddInterface, the action calls $object->add(null) and then unconditionally shows $this->Flash->success('Job X added').

But add() returns void. Some tasks silently do nothing when required configuration is missing. The canonical case is EmailTask::add():

public function add(?string $data): void {
    $adminEmail = Configure::read('Config.adminEmail');
    if ($adminEmail) {
        $this->QueuedJobs->createJob('Queue.Email', $data);
        $this->io->success('OK, job created for email ...');
        return;
    }
    $this->io->warn('Queue Email Task cannot be added via Console without `Config.adminEmail` being set.');
    // ... more $this->io->out() that go to ConsoleIo (invisible in web context)
}

When Config.adminEmail is not set:

  • add() writes a warning via $this->io (ConsoleIo — invisible in a web request)
  • no job is created
  • the controller still shows a green success flash

Result: the operator sees "Job Queue.Email added" but no row appears in the queue. Very confusing to debug.

Fix

Measure the QueuedJobs count before and after invoking the task. If the count didn't change, show an error flash instead of a success flash — and point the operator at the likely config gap.

+$before = $this->QueuedJobs->find()->count();
 if ($object instanceof AddInterface) {
     $object->add(null);
 } else {
     $this->QueuedJobs->createJob($job);
 }
+$after = $this->QueuedJobs->find()->count();

-$this->Flash->success('Job ' . $job . ' added');
+if ($after > $before) {
+    $this->Flash->success('Job ' . $job . ' added');
+} else {
+    $this->Flash->error(
+        'Job ' . $job . ' could not be added — the task did not create a job. '
+        . 'Check configuration (e.g. Config.adminEmail for Queue.Email) and server logs.',
+    );
+}

This keeps AddInterface::add() non-breaking (still void). It's a small count delta check that handles any future task with similar silent-no-op behavior.

AddInterface::add() returns void and may silently skip queuing a job
when required configuration is missing — most notably EmailTask, which
does nothing when Config.adminEmail is not set.

Previously the controller showed a green success flash regardless,
making it look like the admin UI had queued a job when it hadn't.

Now we count QueuedJobs before/after invoking the task. If the count
did not increase, we show an error flash pointing the operator at the
likely config gap, instead of falsely reporting success.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 22, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.14%. Comparing base (5410512) to head (7a7e7f6).

Files with missing lines Patch % Lines
src/Controller/Admin/QueueController.php 50.00% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #478      +/-   ##
============================================
- Coverage     77.22%   77.14%   -0.08%     
- Complexity      949      950       +1     
============================================
  Files            45       45              
  Lines          3196     3216      +20     
============================================
+ Hits           2468     2481      +13     
- Misses          728      735       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark dereuromark merged commit bd2ccf0 into master Apr 22, 2026
16 checks passed
@dereuromark dereuromark deleted the fix-addjob-silent-failure branch April 22, 2026 23:10
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