I am attempting to create a scheduled function in google cloud which starts from an event sent from a cloud function trigger, runs for a period of time, and then stops based on a condition or another event
Trigger -> Start scheduled function -> run on crontab schedule until condition met -> stop scheduled function
It looks like I can use Pubsub and EventARC to do this, by creating a scheduled function which is subscribed to a topic within Pubsub and then start and stop the function based on the messages sent.
Can anyone point me towards an example project or some documentation which describes this architecture in detail?
Implicitly publish message to topic from Cloud trigger:
const messageId = await pubSubClient
.topic(
`my_topic_name`
)
.publishMessage({ data });

The following code will produce the desired result:
It uses Cloud Scheduler to create a scheduled job on the fly and then cancels the job once a certain condition is met