Skip to content

Refactor/single process multiple services#785

Draft
renatomaia wants to merge 24 commits into
next/2.0from
refactor/SingleProcessMultipleServices
Draft

Refactor/single process multiple services#785
renatomaia wants to merge 24 commits into
next/2.0from
refactor/SingleProcessMultipleServices

Conversation

@renatomaia

@renatomaia renatomaia commented Jun 23, 2026

Copy link
Copy Markdown
  • New service runtime pieces:

    • ServicesSupervisor to manage several services together in a single-process, handle OS signals, propagate stop/reload, and join child errors.

    • Overview of changes introduced:

      • Supervisor to manage the system process. It is responsible for:
        • Manage the initialization of the services by calling factory functions that shall create, validate configuration values, and initialize the services.
        • Handle returned errors by outputing them into the log.
        • Provide a clear protocol for services to detect and query the process terminzation through a context.Context. There is no service.stopping stage any more. Moreover, there is no more a Stop method to notify service that is shall terminate. Services must watch the proper context.Context.Done to do what was done in Stop (ex. terminate a HTTP server or a time ticker).
        • Provide an API for services to request the termination of the process (method Stop).
        • Watch and handle process signals that provide an API to system managers to control the process (SIGINT, SIGTERM). The support for SIGHUP was not used and was discarded.
        • Provide a HTTP interface to check on the health of the process and its services (telemetry).
      • Service Implementation:
        • A custom Alive method for each service as not used and was removed. The ${process}/livez endpoint is implemented by the Supervisor and becomes true whenever the Supervisor starts running the services, regardless whether they are fully up or not. It becomes false whenever the Supervisor is stopped, regardless whether the services have fully terminated or not.

        • The Reload method was not used and was discarded.

        • [THIS IS NOT GOOD] A new Teardown method is introduced to allow services to release resources before the Supervisor finishes the system process. The only service using this is the Advancer that uses it to close the Machine Manager.

    • TickServiceTemplate for tick-based services:

      • Advancer
      • Claimer
      • EMV Reader
      • PRT
      • Validator
    • HTTPServiceTemplate for HTTP-backed services:

      • JSON-RPC
      • Inspector: now uses the same hardening path and generic HTTP service startup/shutdown behavior.
      • Telemetry: was refactored as a built-in service managed by a Supervisor.
  • Error handling and lifecycle behavior were tightened throughout:

    • Use combined errors with errors.Join instead of []error.
    • Shutdown is now driven by context cancellation instead of ad hoc service-stop signaling.
    • Child-service failures are propagated through the supervisor.

@renatomaia renatomaia requested review from mpolitzer and vfusco June 23, 2026 12:58
@renatomaia renatomaia self-assigned this Jun 23, 2026
@renatomaia renatomaia force-pushed the refactor/SingleProcessMultipleServices branch 2 times, most recently from 3cf0490 to 758ef1a Compare June 25, 2026 22:52
@renatomaia renatomaia force-pushed the refactor/SingleProcessMultipleServices branch from 758ef1a to 426dd48 Compare June 26, 2026 13:53
@renatomaia renatomaia marked this pull request as draft July 8, 2026 18:08
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