-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Background tasks #44
base: main
Are you sure you want to change the base?
Background tasks #44
Conversation
@@ -192,6 +206,18 @@ def _app_layer(self) -> ops.pebble.LayerDict: | |||
services[self._workload_config.service_name]["override"] = "replace" | |||
services[self._workload_config.service_name]["environment"] = self.gen_environment() | |||
|
|||
for service_name, service in services.items(): | |||
# Add environment variables to all worker processes. | |||
if service_name.endswith(WORKER_SUFFIX): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we should be case-insensitive here?
service["environment"] = self.gen_environment() | ||
# For scheduler processes, add environment variables if | ||
# the scheduler should run in the unit, disable it otherwise. | ||
if service_name.endswith(SCHEDULER_SUFFIX): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here regarding case sensitivity
@@ -94,6 +94,7 @@ def test_go_environment_vars( | |||
log_files=[], | |||
metrics_target=f"*:{framework_config.metrics_port}", | |||
metrics_path=framework_config.metrics_path, | |||
unit_name="go/0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this change for Flask, Django and go tests, but not for fast API?
Test coverage for dae8563
Static code analysis report
|
Applicable spec:
ISD181 - Background tasks in 12 factor apps
Overview
This PR implement background services in 12 factor apps, using the
paas-app-charmer
library.Services defined in
rockcraft.yaml
with their name ending in-worker
will be injected the same environment variables as the main service and will these background services will run in all units.Services defined in
rockcraft.yaml
with their name ending in-scheduler
will be injected the same environment variables as the main service, but will only run in the unit ending in name 0. This pod will always exists if there at least one unit (juju does not set .spec.ordinals.start, see here for reference.The integration test for the PR is complex, as it uses Celery beat and Celery workers. The Celery beat will send tasks to the workers, with an argument that is the Celery beat hostname. The Celery workers will put in a Redis set the hostname of the beat scheduler (received as an argument) and its own hostname in another set. Checking the sets we can see how many schedulers and worker services are working in all the units in the application.
As a simpler alternative, it could be possible to directly check which services are started in each unit and if they contain environment variables.
Documentation will be handled in different PRs/posts.
Rationale
Juju Events Changes
Module Changes
Library Changes
Checklist
src-docs
urgent
,trivial
,complex
)