Service
Represents a long-running background service deployment on Datatailr.
A service runs continuously (e.g., an API server, a message consumer, or any always-on process). It is restarted automatically if it exits.
Example
from datatailr import Service
# service.py
from flask import Flask
app = Flask(__name__)
@app.route("/health")
def health_check():
return "OK"
# Service entrypoints receive the port from Datatailr.
def run_server(port):
app.run("0.0.0.0", port=int(port), debug=False)
svc = Service(
name="Simple Service",
entrypoint=run_server,
python_requirements=["flask"],
)
svc.run()
Parameters:
-
(namestr) –Display name for the service.
-
(entrypointCallable) –The callable (function) that starts the service.
-
(environmentEnvironment | None, default:DEV) –Target environment for the deployment.
-
(imageImage | None, default:None) –Pre-configured container Image.
-
(run_asstr | User | None, default:None) –User or username to run the service as.
-
(resourcesResources, default:Resources()) –CPU and memory resources for the container.
-
(aclACL | None, default:None) –Access control list.
-
(python_versionstr, default:'3.12') –Python version for the container image.
-
(python_requirementsstr | List[str], default:'') –Python dependencies (see
Image). -
(build_script_prestr, default:'') –Dockerfile commands to run before installing requirements.
-
(build_script_poststr, default:'') –Dockerfile commands to run after installing requirements.
-
(env_varsdict[str, str | int | float | bool] | None, default:None) –Environment variables passed to the running container.
-
(get_existingbool, default:False) –If
True, update an existing job definition. -
(versionstr | int | None, default:None) –The version of the job to get.
-
(budgetBudget | str | None, default:None) –Optional spend budget as
Budget("name")or a namestr. Will be set to the 'default' budget if not provided.