Skip to content
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

feat: allow to be run on a cron within the docker container #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

iloveitaly
Copy link
Contributor

No description provided.

Copy link
Owner

@evanpurkhiser evanpurkhiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Months later I am settled in after my move and can review this hahaha 😆

@@ -1,9 +1,11 @@
FROM python:3.11-alpine
FROM python:3.11
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not able to keep it on alpine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm I can't remember the context here, but I think scheduling breaks when not on alpine?

@@ -18,8 +20,10 @@ RUN pdm install

# Add python source
COPY venmo_auto_cashout /app/venmo_auto_cashout/
RUN pdm install
RUN pdm install --production
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 0389b38

@@ -1,8 +1,8 @@
import sqlite3
import argparse
from os import getenv
from time import sleep
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops c59f541

Comment on lines +98 to +101
# output the date and time so when this is running on a cron we know the last time it was run
output(f"Running venmo_auto_cashout at {datetime.now()}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe add this to the script that runs via cron instead?

else
# `-l` ensures that /etc/profile is picked up by the sh subshell
# stdout redirect ensures logs are redirected to the parent process https://snippets.aktagon.com/snippets/945-how-to-get-cron-to-log-to-stdout-under-docker-and-kubernetes
echo "${SCHEDULE} root sh -lc 'cd ${PWD} && $(which pdm) run venmo-auto-cashout' > /proc/1/fd/1 2>&1" >>/etc/crontab
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the /proc/1/fd/1 magic for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this stdout of cron is not sent to the docker container's stdout

dockerStart.sh Outdated
Comment on lines 15 to 16
# debian slim does not include cron by default, this must be installed via Dockerfile
# additionally, busybox does *not* add the cron process, so we must use the debian cron package
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have this comment here? The dockerfile installs it so I don't think we need to include this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, removed

printenv | awk -F= '{print "export " "\""$1"\"""=""\""$2"\"" }' >>/etc/profile

if [[ ${SCHEDULE} == "NONE" ]]; then
pdm run venmo-auto-cashout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be

Suggested change
pdm run venmo-auto-cashout
exec pdm run venmo-auto-cashout

and then we don't need the else case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not following: why wouldn't we need the else case here? The else is for running this on a schedule.

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