Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AppsDevTeam/background-queue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: processWaitingJobs
Choose a base ref
...
head repository: AppsDevTeam/background-queue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 18 commits
  • 16 files changed
  • 4 contributors

Commits on Mar 25, 2026

  1. Merge pull request #59 from AppsDevTeam/processWaitingJobs

    Process waiting jobs
    thorewi authored Mar 25, 2026
    Configuration menu
    Copy the full SHA
    2c876d1 View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2026

  1. Configuration menu
    Copy the full SHA
    900faca View commit details
    Browse the repository at this point in the history

Commits on Jun 16, 2026

  1. Update composer.json

    thorewi authored Jun 16, 2026
    Configuration menu
    Copy the full SHA
    d7940d3 View commit details
    Browse the repository at this point in the history

Commits on Jun 18, 2026

  1. Add CLAUDE.md with guidance for Claude Code

    Documents the architecture of this background-queue library:
    - Dev commands (docker-up, init, test)
    - Core class and entry points (BackgroundQueue, processJob)
    - Two operating modes (cron vs broker)
    - Job state machine with exception-to-state mapping
    - serialGroup and WAITING mechanism
    - Implementation details (dual connection, middleware, broker abstraction)
    - Console commands and bulk insert
    
    Helps future Claude Code sessions get productive in the project faster.
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    cbfd0ea View commit details
    Browse the repository at this point in the history
  2. Fix makefile config target to use .env.example

    The config target should copy from .env.example, not .env.local.
    This ensures the base configuration template is available and consistent.
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    b6c7cd9 View commit details
    Browse the repository at this point in the history
  3. Stop tracking generated Codeception test file

    tests/Support/_generated/IntegrationTesterActions.php je automaticky
    generovaný soubor vytvářený Codeception při spuštění testů. Přidáno
    do .gitignore, odebrán z trackingu.
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    d5d32fd View commit details
    Browse the repository at this point in the history
  4. Fix integration tests compatibility with BackgroundQueue API changes

    - Producer helper: update publish() signature (string $id, int $priority), add publishDie()
    - Logger: add void return types to all PSR-3 methods
    - BackgroundQueueTest: use Connection objects instead of DSN strings, fix publish()
      calls (ModeEnum::NORMAL, milliseconds instead of DateTimeImmutable), use reflection
      for private fetchAll/createQueryBuilder, update test expectations for delayed jobs,
      fix WaitingException test state to FINISHED, refetch entity after processJob(),
      fix JobNotFoundException assertions
    - ConsumeCommandTest: use Connection objects, update error message expectation
    - .gitignore: add tests/Support/_generated (auto-generated Codeception file)
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    693c175 View commit details
    Browse the repository at this point in the history
  5. Add detailed test plan for priority + serialGroup, including a full b…

    …roker-mode test
    
    Expands the "Návrh testů" section in docs/priority-serialgroup.md from a single
    reproduction test into a detailed set of six tests covering every aspect of the
    proposed solution:
    
    - Test 1: Jobs without serialGroup (regression - nothing should change)
    - Test 2a/2b: Ordering by (priority, ID) - unit + end-to-end cron mode
    - Test 3: PROCESSING clause (mutual exclusion) - serialization regression
    - Test 4: Group lock - acquire/release primitive with two connections
    - Test 5: Conditional claim in save() - RabbitMQ redelivery race
    - Test 6: Full broker-mode end-to-end - whole loop process → publish → consume → waiting
    
    Also documents the prerequisites: extending getBackgroundQueue() (priorities),
    extending the Mailer helper (processRecording + static $processOrder), direct raw DB
    connection access to simulate states, and extending the Producer helper (priority
    queues for Test 6).
    
    Coverage includes the interaction with _processWaitingJobs() and
    findOldestUnfinishedJobIdsByGroup() that the other tests do not exercise on their own.
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    2e6fac1 View commit details
    Browse the repository at this point in the history
  6. Implement integration tests for priority and serialGroup handling

    Add comprehensive test suite covering priority ordering and serial group semantics:
    - Test 1: Verify jobs without serialGroup are unaffected by priority changes
    - Test 2a/2b: Validate predecessor selection by (priority, ID) and order in cron mode
    - Test 3: Ensure PROCESSING clause blocks higher-priority jobs (mutual exclusion)
    - Test 4: Guard for acquireGroupLock/releaseGroupLock implementation
    - Test 5: Guard for conditional claim in save() to prevent double-processing on redelivery
    - Test 6: Full broker-mode end-to-end test through priority queues and WAITING mechanism
    
    Extend test helpers:
    - Mailer: Add processRecording() callback with $processOrder tracking and serial group violation detection
    - Producer: Implement priority queue routing (general_<priority>), consume in priority order
    - BackgroundQueueTest: Add priorities parameter, rawConnection() helper, purge priority sub-queues
    
    All tests currently demonstrate expected behavior: 4 red (reproduce missing fixes), 3 green (guards).
    Viktor Mašíček committed Jun 18, 2026
    Configuration menu
    Copy the full SHA
    8ff1063 View commit details
    Browse the repository at this point in the history

Commits on Jun 19, 2026

  1. Optimize findOldestUnfinishedJobIdsByGroup + harden serialGroup advis…

    …ory lock
    
    Priority-aware head selection uses a JOIN with a derived table instead of a
    DEPENDENT SUBQUERY, eliminating O(W²) complexity and removing the need for a
    composite index. On top of that, the serialGroup advisory lock is hardened so it
    works correctly on both MySQL and PostgreSQL and never aborts a whole process()
    run / consumer on lock contention.
    
    Head selection / query changes:
    - findOldestUnfinishedJobIdsByGroup: rewrite to JOIN-based approach (O(W) linear,
      MySQL+PostgreSQL compatible)
    - Test 7: add deterministic regression test for head-selection logic with a
      priority-gap scenario
    - docs/priority-serialgroup.md: add performance analysis with benchmark table
      (1k-20k rows: ~160x-1100x speedup), compare variants (correlated subquery vs.
      derived table JOIN vs. composite index), explain why variant B was chosen
      (zero write-amplification, no index needed)
    - Test 2b: add sleep between process() calls to respect WAITING job postponement
    - Producer helper: implement delayed-message recirculation model (in-memory TTL
      buffer) to match real Producer behavior and prevent livelock on the
      highest-priority _processWaitingJobs
    
    Advisory lock hardening:
    - PostgreSQL: use single-arg pg_advisory_lock(bigint) with a composed 64-bit key
      ((namespace << 32) | crc32). The two-arg int4 variant would overflow on
      crc32 values > 2^31 ("integer out of range")
    - MySQL: hash serial_group via crc32 into the lock name. GET_LOCK names are
      capped at 64 chars and serial_group is VARCHAR(255), so a long group name
      would make GET_LOCK return NULL and silently fail
    - acquireGroupLock now returns bool instead of throwing. On failure processJob
      re-publishes the job to the broker and returns, so a single lock collision no
      longer aborts the whole process() run / consumer (the job is retried next time;
      in cron mode it is picked up by the next process() run)
    - Test 4: update to the new bool contract; docs updated incl. crc32 collision
      probability estimate (birthday problem over 2^32)
    
    All tests passing (26 tests, 71 assertions). No new indexes added - avoids
    write-amplification from frequent state changes.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
    Viktor Mašíček and claude committed Jun 19, 2026
    Configuration menu
    Copy the full SHA
    7e353b3 View commit details
    Browse the repository at this point in the history

Commits on Jun 20, 2026

  1. Merge pull request #61 from AppsDevTeam/priority-and-serialgroup

    Priority and serialgroup
    thorewi authored Jun 20, 2026
    Configuration menu
    Copy the full SHA
    f21d046 View commit details
    Browse the repository at this point in the history

Commits on Jun 21, 2026

  1. Improve memory handling for background queue processing

    Addresses potential out-of-memory errors when processing a large number of background jobs.
    
    *   Limits the number of background jobs fetched per iteration to 10,000.
    *   Increases the PHP memory limit for the console `process` command to 1GB.
    thorewi committed Jun 21, 2026
    Configuration menu
    Copy the full SHA
    34ec31a View commit details
    Browse the repository at this point in the history
  2. Implement job coalescing for background queue

    Allows jobs to mark overlapping, unstarted jobs within the same serial group as REDUNDANT.
    
    This prevents redundant processing, for example, when a "recalculate from X" job covers the work of later "recalculate from Y (where Y >= X)" jobs.
    thorewi committed Jun 21, 2026
    Configuration menu
    Copy the full SHA
    3142627 View commit details
    Browse the repository at this point in the history
  3. Lower background queue job fetch limit

    Reduces the maximum number of background jobs fetched and processed
    per iteration from 10,000 to 1,000.
    
    While the previous increase to 10,000 aimed to reduce database round-trips,
    processing such a large batch concurrently could still lead to excessive
    memory consumption for specific job types, resulting in out-of-memory
    errors. This adjustment provides a better balance between database
    efficiency and peak memory usage during job execution.
    thorewi committed Jun 21, 2026
    Configuration menu
    Copy the full SHA
    c39ace4 View commit details
    Browse the repository at this point in the history

Commits on Jun 22, 2026

  1. Handle deadlocks in job coalescing

    The `markCoalescedJobsRedundant` operation can encounter transient database deadlocks (1213) during concurrent writes. This could leave jobs stuck in a PROCESSING state.
    
    This change adds a retry mechanism with a back-off delay for the coalesce UPDATE to overcome these transient deadlocks. Additionally, a new index `(serial_group, coalesce_threshold)` is added to optimize the WHERE clause, reducing lock contention and preventing deadlocks by allowing targeted index scans.
    thorewi committed Jun 22, 2026
    Configuration menu
    Copy the full SHA
    748a235 View commit details
    Browse the repository at this point in the history
  2. Mark jobs temporarily failed on persistent coalescing deadlocks

    When the `markCoalescedJobsRedundant` operation fails due to a deadlock
    that persists even after internal retries, the job would otherwise
    remain stuck in a PROCESSING state.
    
    This ensures such jobs are transitioned to TEMPORARILY_FAILED, allowing
    them to be picked up for reprocessing in a subsequent run, preventing
    them from getting permanently stuck.
    thorewi committed Jun 22, 2026
    Configuration menu
    Copy the full SHA
    1c78ab5 View commit details
    Browse the repository at this point in the history

Commits on Jun 28, 2026

  1. Allow dynamic AMQP arguments based on queue name

    Introduces an optional `queueArguments` parameter to the `Manager` constructor. This enables applying specific AMQP arguments, such as `x-single-active-consumer`, to queues whose names contain a defined string.
    
    This provides more granular and flexible control over queue behavior without requiring separate queue parameter definitions for each unique configuration.
    thorewi committed Jun 28, 2026
    Configuration menu
    Copy the full SHA
    f4c3fe4 View commit details
    Browse the repository at this point in the history
  2. Order background jobs by ID for consistent processing

    Ensures jobs are processed in a predictable and consistent order, preventing potential starvation of older jobs.
    thorewi committed Jun 28, 2026
    Configuration menu
    Copy the full SHA
    fc912a3 View commit details
    Browse the repository at this point in the history
Loading