Skip to content

Commit

Permalink
In skeleton, add worker code
Browse files Browse the repository at this point in the history
  • Loading branch information
shaldengeki committed Jul 30, 2024
1 parent 756565f commit 95f9b48
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
54 changes: 54 additions & 0 deletions skeleton/worker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("//tools/build_rules:cross_platform_image.bzl", "cross_platform_image")
load("//tools/build_rules:py_layer.bzl", "py_oci_image")

py_binary(
name = "binary",
srcs = ["app.py"],
imports = [".."],
main = "app.py",
visibility = ["//:__subpackages__"],
deps = ["//skeleton:config_py"],
)

py_oci_image(
name = "base_image",
base = "@python3_image",
binaries = [
"//scripts:wait_for_postgres",
":binary",
],
cmd = [
"/" + package_name() + "/binary",
],
entrypoint = [
"/scripts/wait_for_postgres",
],
env = {
"FLASK_APP": "app.py",
"FLASK_DEBUG": "True",
"API_PORT": "5000",
"FRONTEND_PROTOCOL": "http",
"FRONTEND_HOST": "frontend",
"FRONTEND_PORT": "5001",
"DB_HOST": "pg",
"DB_USERNAME": "admin",
"DB_PASSWORD": "development",
"DATABASE_NAME": "api_development",
"FITBIT_CLIENT_ID": "testing",
"FITBIT_CLIENT_SECRET": "testing",
"FITBIT_VERIFICATION_CODE": "testing",
"FLASK_SECRET_KEY": "testing",
},
tags = ["manual"],
)

# $ bazel run //skeleton/worker:image_tarball
# $ docker run --rm shaldengeki/skeleton-worker:latest
cross_platform_image(
name = "image",
image = ":base_image",
repo_tags = ["shaldengeki/skeleton-worker:latest"],
repository = "docker.io/shaldengeki/skeleton-worker",
visibility = ["//skeleton/worker:__subpackages__"],
)
Empty file added skeleton/worker/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions skeleton/worker/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time

from fitbit_challenges.config import app, db

max_delay = 10


def main() -> int:
with app.app_context():
while True:
start = time.time()
# Do work here.
delay = (start + max_delay) - time.time()
if delay > 0:
time.sleep(delay)


if __name__ == "__main__":
raise SystemExit(main())

0 comments on commit 95f9b48

Please sign in to comment.