Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@heidmotron
Last active April 9, 2019 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heidmotron/d692670329918f33a4f219a6ec96926e to your computer and use it in GitHub Desktop.
Save heidmotron/d692670329918f33a4f219a6ec96926e to your computer and use it in GitHub Desktop.
Python3 app using cf tasks

Push an app

Push an app with a main web process that runs forever (in this case it does nothing) and there is no healthcheck

Download main.py, http-call.py, and requirement.txt into a directory. Then from that directory, run:

cf push py-simple -b https://github.com/cloudfoundry/python-buildpack.git -c "python main.py"  -u none

Once the app is pushed, you can tail the logs

cf tail -f py-simple

Run a task

Then you can run a task using any other python file that is bundled with the app, like http-call.py:

cf run-task py-simple "python http-call.py"

In the logs, you should see the status of the request print out

2019-04-08T21:27:10.22-0600 [APP/TASK/744dbd64/0] OUT https://pivotal.io STATUS 200
from urllib import request
if __name__ == "__main__":
with request.urlopen("https://pivotal.io") as response:
print("https://pivotal.io STATUS {}".format(response.status))
import time
if __name__ == "__main__":
while True:
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment