Add more
Some checks failed
Gitea Actions Demo Training / Explore-Gitea-Actions (push) Failing after 11s
Some checks failed
Gitea Actions Demo Training / Explore-Gitea-Actions (push) Failing after 11s
This commit is contained in:
42
slides/sbom/python-app-deployment.md
Normal file
42
slides/sbom/python-app-deployment.md
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
# Back to our app: worker.py
|
||||
|
||||
Let's follow our app from code to deployment in a container.
|
||||
|
||||
During each step we'll analyze the software and show some highlights.
|
||||
|
||||
---
|
||||
|
||||
Step 1: The code
|
||||
|
||||
```python
|
||||
import logging
|
||||
import os
|
||||
from redis import Redis
|
||||
import requests
|
||||
import time
|
||||
...
|
||||
redis = Redis("redis")
|
||||
...
|
||||
def work_loop(interval=1):
|
||||
deadline = 0
|
||||
loops_done = 0
|
||||
while True:
|
||||
if time.time() > deadline:
|
||||
log.info("{} units of work done, updating hash counter"
|
||||
.format(loops_done))
|
||||
redis.incrby("hashes", loops_done)
|
||||
loops_done = 0
|
||||
deadline = time.time() + interval
|
||||
work_once()
|
||||
loops_done += 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
try:
|
||||
work_loop()
|
||||
except:
|
||||
log.exception("In work loop:")
|
||||
log.error("Waiting 10s and restarting.")
|
||||
time.sleep(10)
|
||||
```
|
||||
Reference in New Issue
Block a user