Skip to content

fog-plugins v1.6.3

Choose a tag to compare

@mastacontrola mastacontrola released this 14 Aug 11:10
· 27 commits to main since this release

Adds the first worked example of a plugin background task.

FOG 1.6.0-beta.3349 introduces FOGPluginRunner, a core-owned daemon that runs work a plugin declares at <plugin>/tasks/*.task.php — see ADR 0010. Until now everything a plugin could register ran inside a request, so a plugin could react to an event but could not poll, reconcile, expire or retry.

helloworld/tasks/helloworldheartbeat.task.php is the worked example: it counts the plugin's rows on a schedule and logs the total. Deliberately read-only, and deliberately without a try/catch, since the runner catches Throwable and names the plugin and task in the log.

Its comments carry the three rules the runner imposes, none of which are guessable from the class:

  • it runs as the web user, not root — installing a plugin grants exactly what installing a plugin already granted;
  • every plugin's tasks share one process and run one at a time, so bound your network and database calls;
  • run() must be idempotent — next-run times live in memory, so a restart makes every task immediately due.

Plus the naming trap: a task class shares one global namespace with every class in FOG, so tasks/host.task.php would collide with the core Host model. Prefix with your plugin name.

Requires FOG 1.6.0-beta.3350 or newer. The runner itself landed in beta.3349, but PluginTask::log() — which the example calls — landed one build later; on beta.3349 the task is discovered and then fails with an undefined method, which the runner catches and logs rather than crashing on. On anything older the runner does not exist, the .task.php extension is not autoloaded, and the file is simply inert — nothing breaks, the task just never runs.

Also corrects the persistentgroups line in the README: it does not keep group membership across re-registration; its trigger copies image, AD, printer and location settings onto a joining host from a template host whose name matches the group's.

Only helloworld/tasks/ and README.md differ from v1.6.2.