1- ## Setup stream-looper VM and topic
1+ # Setup stream-looper VM and topic
2+
3+ ## Create the Pub/Sub topic and allow public subscriptions
24
3- Create the topic and allow public subscriptions
45``` bash
56PROJECT=$GOOGLE_CLOUD_PROJECT
67TOPIC=" ztf-loop"
@@ -15,7 +16,8 @@ gcloud pubsub topics get-iam-policy $topic_path --format yaml > $fnametmp
1516gcloud pubsub topics set-iam-policy $topic_path $fname
1617```
1718
18- Create the VM and setup the consumer simulator
19+ ## Create the VM and setup the consumer simulator
20+
1921``` bash
2022vmname=" stream-looper"
2123zone=" us-central1-a"
@@ -34,21 +36,44 @@ gcloud compute instances create "$vmname" \
3436gcloud compute instances add-metadata " $vmname " --zone=" $zone " --metadata=startup-script=" "
3537
3638# ssh in
37- gcloud compute ssh $vmname
38- screen
39- ipython3
39+ # gcloud compute ssh $vmname
4040```
41+
42+ ### Set a startup script to run consumer simulator indefinitely
43+
44+ Python script to trigger at startup.
45+ Save the following code to a root-executable file at
46+ /home/consumer_sim/run-looper-indefinitely.py:
47+
4148``` python
49+ # !/usr/bin/env python3
50+ # -*- coding: UTF-8 -*-
4251from broker_utils import consumer_sim as bcs
4352
44- # publish 1 alert every 5 seconds
45- alert_rate = (12 , ' perMin' )
53+ # set args to publish 1 alert every second
54+ alert_rate = (60 , ' perMin' )
4655kwargs = {
4756 ' instance' : None ,
48- ' runtime' : (1 , ' hr ' ),
49- ' publish_batch_every' : (5 , ' sec' ),
50- ' sub_id' : ' ztf-alerts-reservoir-v050 ' ,
57+ ' runtime' : (1 , ' night ' ),
58+ ' publish_batch_every' : (1 , ' sec' ),
59+ ' sub_id' : ' ztf-alerts-reservoir' ,
5160 ' topic_id' : ' ztf-loop' ,
61+ ' auto_confirm' : True ,
5262}
53- bcs.publish_stream(alert_rate, ** kwargs)
63+
64+ # run indefinitely
65+ while True :
66+ bcs.publish_stream(alert_rate, ** kwargs)
67+ ```
68+
69+ Set a startup script to execute the python file in a background thread:
70+ ``` bash
71+ startupscript=" #! /bin/bash
72+ dir=/home/consumer_sim/
73+ fname=run-looper-indefinitely
74+ nohup python3 \$ {dir}\$ {fname}.py >> \$ {dir}\$ {fname}.out 2>&1 &
75+ "
76+
77+ # set the startup script
78+ gcloud compute instances add-metadata " $vmname " --metadata=startup-script=" $startupscript "
5479```
0 commit comments