Problem/Motivation

A job runs only when its schedule says. Work often arrives at a moment the site knows about (a webhook stored an event, an invitation was sent, a queue got its first item), and then waits for the job's next turn. Making that wait short means running the job every few seconds, which is a process and a full Drupal bootstrap each time, mostly finding nothing to do. The worker only hears from the site at its refresh (one minute at the least), so the site has no cheap way to say "now".

Proposed resolution

  • A druker.wake service (Wake::wake($job), a job or its id) and drush druker:wake <id|name>. A signal is an empty file named after the job's id, in a wake directory.
  • The directory is $settings['druker_wake_dir']: a path or stream URI, or FALSE to switch waking off. By default it is private://druker/wake when the site has a private file system, and otherwise a directory of the site's own under temporary://. The schedule tells the worker where it is, as a new top-level wake_dir in drush druker:jobs.
  • The worker lists the directory on every one-second tick, which costs a directory read and no Drush call. It claims a signal by removing its file, so workers sharing the directory run the job once, and it starts the job at once.
    • A running job keeps its signal and runs again when it finishes; a job that allows overlap starts alongside.
    • A one-time job already done is not run again.
    • A signal no worker claims is removed after an hour.
  • A signal that cannot be written is logged, and the job runs at its next turn: the schedule stays the floor.
  • drush druker:check says when waking is off or the directory cannot be written.
  • Contract: wake_dir in JobManager::getJobsForServer(), the worker's Schedule struct, and examples/sample-output.json. An older worker ignores it, and a newer worker against an older site does not wake.
  • Tests: worker/wake_test.go, an end-to-end supervise test, Kernel WakeTest, and JobManagerTest.

Issue fork druker-3637503

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

valic created an issue. See original summary.

valic’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.