vania-janet/multiturn-rag-retrieval-data huggingface dataset:
After your app is ready, create a subscription to the cron event producer and connect it to your app with the [ibmcloud ce sub cron create](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-cron-create) command.

The following example creates a cron subscription that is called cron-sub and specifies the cron-app application as its destination. The subscription uses the --data option to include a JSON string in the cron event. It also specifies the cron schedule by using the --schedule option with a value of * * * * * to send an event every minute of every day to the cron-app application.

ibmcloud ce sub cron create --name cron-sub --destination cron-app --data '{"mydata":"hello world"}' --schedule '* * * * '

Run ibmcloud ce sub cron get -n cron-sub to find information about your subscription.

Example output

In this output, you can see that the subscription name, destination, schedule, and data are correct.

Getting cron event subscription 'cron-sub'...
OK

Name: cron-sub
ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Project Name: myproject
Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111
Age: 2m18s
Created: 2021-03-14T13:21:13-05:00

Destination Type: app
Destination: cron-app
Schedule: * * * * 
Time Zone: UTC
Data: {"mydata":"hello world"}
Ready: true

Events:
Type Reason Age Source Messages
Normal FinalizerUpdate 65s pingsource-controller Updated "cron-sub" finalizers





 Step 4: Testing your subscription 

After you successfully subscribed your app to your cron event, look at the logs to see whether it works.
You can use the [ibmcloud ce subscription kafka update](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-kafka-update) command to update the values for the Kafka subscription. However, you cannot modify the value for the consumer group with this command. If you want to update the subscription to reference a different topic, make sure that the Kafka topic exists before you update the subscription.





 Step 6: Clean up for Kafka subscription tutorial 

Ready to delete your Kafka subscription, the sending and receiving apps, and the secret? You can use the [ibmcloud ce app delete](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-delete), the [ibmcloud ce sub kafka delete](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-kafka-delete), and the [ibmcloud ce sub kafka delete](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-secret-delete) commands. You can optionally use the -f option to force the delete of the component without confirmation.

When you delete the Kafka subscription, the delete does not delete the app that is referenced by the subscription.

To remove your subscription,

ibmcloud ce sub kafka delete --name mykafkasubscription -f

To remove your Kafka message-receiving application,

ibmcloud ce app delete --name kafka-receiver-app -f

Similarly, you can remove the kafka-sender-app.

ibmcloud ce app delete --name kafka-sender-app -f

To remove the kafka-subscription-secret,

ibmcloud ce secret delete --name kafka-subscription-secret -f

Ready to delete your service instance for Event Streams service instance?
For more information about headers and body, see [HTTP headers and body information for events](https://cloud.ibm.com/docs/codeengine?topic=codeengine-eventing-cosevent-producersub-header-body-cos).

Note that subscriptions can affect how an application scales. For more information, see [Configuring application scaling](https://cloud.ibm.com/docs/codeengine?topic=codeengine-app-scale).





 Step 5: Testing your subscription 



1. Upload a .txt file to your bucket. For example, you can use the [ibmcloud cos object-put](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-cli-plugin-ic-cos-cliic-upload-object) command to upload the sample.txt object to a bucket with sample as the value for --key.

ibmcloud cos object-put --bucket mybucket --key sample --body sample.txt
2. View the processed event by using the [ibmcloud ce app logs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-logs) command.

ibmcloud ce app logs --name cos-app

Example output

This command returns log files that include information about the event that was forwarded to your destination app. From the following output, you can see that a Write operation was performed on the sample object in the bucket named mybucket.
Choose your interval from the provided patterns or provide your own custom cron expression, such as 0 0 * * , which specifies for the event to occur every day at midnight. For this example, select the schedule pattern for every day, every hour, every minute. Notice that the cron expression is generated for you. The day, hour, and minute patterns and the Cron expression are in Coordinated Universal Time (UTC). If you do not specify a schedule, then this event subscription sends an event every minute. A list of upcoming scheduled events is displayed. Notice that these upcoming scheduled events are displayed in your time zone. Click Next to proceed.
3. For Custom event data, provide data to include in the body of your event message. You can specify the message as plain text or in base64 format. For this example, specify the text, hello stranger as the body of the event message. If the message is in base64 format, you can choose to have the message decoded when the event is sent. You can also specify the content type for your custom event data. Click Next to proceed.
4. For Event consumer, specify the application or job to receive events. Notice that you can choose from a list of defined applications and jobs. For this example, use the myjob job that references the icr.io/codeengine/codeengine image. If you have not yet created your job, you can specify the name of your job and [create your job](https://cloud.ibm.com/docs/codeengine?topic=codeengine-job-plan) after you create the Periodic timer (cron) subscription. Click Next to proceed.
5. For Summary, review the settings for your Periodic timer event subscription and make changes if needed. When ready, click Create to create the Periodic timer (cron) subscription.



5. Now that your Periodic timer (cron) subscription is created, go to the Event subscriptions page to [view a listing of defined subscriptions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-subscribe-cronview-eventing-cron-app-ui).
View the processed event by using the [ibmcloud ce app logs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-logs) command.

ibmcloud ce app logs --name cos-app

Example output

This command returns log files that include information about the event that was forwarded to your destination app. From the following output, you can see that a Write operation was performed on the sample object in the bucket named mybucket.

Body: {"bucket":"mybucket","endpoint":"","key":"sample","notification":{"bucket_name":"mybucket","content_type":"text/plain","event_type":"Object:Write","format":"2.0","object_length":"1960","object_name":"sample","request_id":"103dd6f7-dd7b-4f49-86db-c2ff4b678b0a","request_time":"2021-02-11T16:57:42.373Z"},"operation":"Object:Write"}







 Step 6: Update your Object Storage subscription 

Now you know that your Object Storage subscription was created successfully and that the Object Storage subscription is ready to serve events, you can update the Object Storage subscription with the [ibmcloud ce sub cos update](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-cos-update) command. For example, you can change your subscription to run only when specific operations happen on a subset of objects in the bucket.



1. Update the Object Storage subscription to forward events only when delete operations happen on files with a name prefix of test.

ibmcloud ce sub cos update --name cos-sub --event-type delete --prefix test
2.
Check the status of the Redis operator:

oc get opreq common-service-redis -n ibm-common-services -o jsonpath='{.status.phase} {"n"}'
2. If the Redis operand request is stuck in Pending status, delete the operand request:

oc delete opreq watson-assistant-redis -n ibm-common-services
3. Create the Redis subscription. Create one of the following two subscriptions, depending on whether you are using.

a) Export the project that contains the IBM Cloud Pak® for Data operator:

export OPERATOR_NS=ibm-common-services|cpd-operators Select the project that contains the Cloud Pak for Data operator

b) Create the subscription. Choose one of the following two subscriptions, depending on how you are using the IBM Entitled Registry:



* IBM Entitled Registry from the ibm-operator-catalog:



cat <<EOF | oc apply --namespace $OPERATOR_NS -f -
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: ibm-cloud-databases-redis-operator
spec:
name: ibm-cloud-databases-redis-operator
source: ibm-operator-catalog
sourceNamespace: openshift-marketplace
EOF



* IBM Entitled Registry with catalog sources that pull specific versions of the images:



cat <<EOF | oc apply --namespace $OPERATOR_NS -f -
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: ibm-cloud-databases-redis-operator
spec:
name: ibm-cloud-databases-redis-operator
source: ibm-cloud-databases-redis-operator-catalog
sourceNamespace: openshift-marketplace
EOF
4. Validate that the operator was successfully created.

a) Run the following command to confirm that the subscription was applied:
View the processed event by using the [ibmcloud ce app logs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-logs) command.

ibmcloud ce app logs --name cos-app

Example output

This command returns log files that include information about the event that was forwarded to your destination app. From the following output, you can see that a Delete operation was performed on the .txt object in the bucket named mybucket.

Body: {"bucket":"mybucket","endpoint":"",""key":"test2.txt","notification":{"bucket_name":"mybucket","event_type":"Object:Delete","format":"2.0","object_length":"41","object_name":"test2.txt","request_id":"c1099857-f1f3-4d74-9ac4-8d374582f77d","request_time":"2021-09-15T15:22:01.205Z"},"operation":"Object:Delete"}







 Step 7: Clean up for Object Storage tutorial 

Ready to delete your Object Storage subscription and your app? You can use the [ibmcloud ce app delete](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-delete) and the [ibmcloud ce sub cos delete](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-cos-delete) commands.

To remove your subscription,

ibmcloud ce sub cos delete --name cos-sub

To remove your application,

ibmcloud ce app delete --name cos-app

Ready to delete your Object Storage bucket and service instance?
Add another environment variable to [reference the full secret](https://cloud.ibm.com/docs/codeengine?topic=codeengine-secretsecret-ref-ui), kafka-subscription-secret. This secret contains the credentials for password.



3. (optional) In the Runtime settings section, specify 1 for the minimum number of instances so that the app always has an instance that is running and does not scale to zero. Configuring the app to always have a running instance is useful when you view logs. If you are running in a production environment, consider the cost of keeping a running instance of your app or whether you want Code Engine to autoscale to zero. By default, the app scales to zero when not in use.
4. Click Create to create and deploy your app.



2. Confirm that this app is in ready status.







 Creating a Code Engine app to send events with the CLI 

To create the kafka-sender-app application with the CLI, use the following commands.



1. [Create a Code Engine application](https://cloud.ibm.com/docs/codeengine?topic=codeengine-deploy-appdeploy-app-cli) that is called kafka-sender-app with the following information.



* Specify the --image option to reference the icr.io/codeengine/kafka-sender container image. This image is built from sender.go, which is available from the [Samples for IBM Cloud Code Engine GitHub repo](https://github.com/IBM/CodeEngine/tree/main/kafka). This sample sender app requires the password credentials that are stored in your kafka-subscription-secret, and it requires the BROKERS environment variable.
* Specify the --env-from-secret option to reference the full secret, kafka-subscription-secret, which contains the password credentials.
* Specify the --env option to add a literal environment variable, BROKERS, and provide the name of one of the broker hosts that are listed in the details of the service credentials in the Event Streams service instance.
ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Project Name: myproject
Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111
Age: 2m21s
Created: 2021-08-31T16:00:49-04:00

Destination Type: app
Destination: myapp
Schedule: /2 * * * 
Time Zone: UTC
Ready: true

Events:
Type Reason Age Source Messages
Normal PingSourceSynchronized 7s (x3 over 13m) pingsource-controller PingSource adapter is synchronized

Want to try a tutorial? See [Subscribing to Periodic timer (cron) events](https://cloud.ibm.com/docs/codeengine?topic=codeengine-subscribe-cron-tutorial). Looking for more code examples? Check out the [Samples for IBM Cloud Code Engine GitHub repo](https://github.com/IBM/CodeEngine).





 Viewing event information for an application from the console 

To view information about your event subscriptions,



1. From the [Code Engine Projects page](https://cloud.ibm.com/codeengine/projects), go to your project.
2. From the Overview page, click Event subscriptions to view a listing of defined subscriptions.



If your application prints information to log files, as the sample cron application does, then view the log files for your event consumer application. See [Viewing application logs from the console](https://cloud.ibm.com/docs/codeengine?topic=codeengine-view-logsview-applogs-ui).





 Viewing event information for an application with the CLI
Schedule: * * * * 
Time Zone: UTC
Data: {"mydata":"hello world"}
Ready: true

Events:
Type Reason Age Source Messages
Normal FinalizerUpdate 65s pingsource-controller Updated "cron-sub" finalizers





 Step 4: Testing your subscription 

After you successfully subscribed your app to your cron event, look at the logs to see whether it works.

Get the logs for the app with the [ibmcloud ce app logs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-logs) command.

ibmcloud ce app logs --name cron-app

Example output

In the following output, you can see that the date and time that the event was received as well as the HTTP Headers and the HTTP Body JSON that was passed in when the subscription was created.

2021-01-21 20:15:00 - Received:
Header: Accept-Encoding=[gzip]
Header: Ce-Id=[7de01e8e-84dc-4409-ad56-90d6e391397c]
Header: Ce-Source=[/apis/v1/namespaces/50d38123af5/pingsources/cron-sub]
Header: Ce-Specversion=[1.0]
Header: Ce-Time=[2021-01-21T20:15:00.392503458Z]
Header: Ce-Type=[dev.knative.sources.ping]
Header: Content-Length=[24]
Header: Content-Type=[application/json]
Header: Forwarded=[for=172.30.118.174;proto=http, for=172.30.95.204]
Header: K-Proxy-Request=[activator]
Header: Traceparent=[00-1bf4b6b1d67f278a4b827e4e00f0cf7c-cbce9df0faedd812-00]
Thus, if you use the --data option or the --data-base64 option, you can send a maximum of 4096 bytes. For more information, see [Limits and quotas for Code Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits).
* Cron subscriptions use the UTC time zone by default. You can change the time zone by specifying the --time-zone option with the sub cron create or the sub cron update commands. For valid time zone values, see the [TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Note that if you create a subscription by using kubectl and do not specify a time zone, then the UTC time zone is assigned.
* If you have not yet created your app or job event consumer, use the --force option with the sub cron create command to force the create of the cron event subscription. You can specify the name of your application or job and [create your application](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-application-create) or [create your job](https://cloud.ibm.com/docs/codeengine?topic=codeengine-job-plan) after you create the cron subscription.



To verify that your cron subscription was successfully created, run the ibmcloud ce sub cron get --name mycronevent command.

Example output

Getting cron source 'mycronevent'...
OK

Name: mycronevent
ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Project Name: myproject
Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111
Age: 2m21s
Created: 2021-03-14T13:37:51-05:00

Destination Type: app
Destination: myapp
Schedule: 0 0 * * 
Time Zone: UTC
Ready: true
2022/03/31 22:19:46 Header: X-Request-Id=[abcdeb4e-c5ac-abcd-abcd-60e6278abcde]
2022/03/31 22:19:46 Event data: test1: 1

Note that log information for apps lasts for only one hour. For more information about viewing logs for apps (or jobs), see [Viewing logs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-view-logs).







 Step 5: Updating your subscription 

To update an event subscription with the CLI, use the [ibmcloud ce subscription kafka update](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-kafka-update) command. The following example updates the topic name.

ibmcloud ce sub kafka update -n mykafkasubscription --topic kafka-topic2

You can use the [ibmcloud ce subscription kafka update](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-kafka-update) command to update the values for the Kafka subscription. However, you cannot modify the value for the consumer group with this command. If you want to update the subscription to reference a different topic, make sure that the Kafka topic exists before you update the subscription.





 Step 6: Clean up for Kafka subscription tutorial 

Ready to delete your Kafka subscription, the sending and receiving apps, and the secret?
To create the kafka-subscription-secret secret, add a literal environment variable for password, and username. For more information, see [create a secret with the CLI](https://cloud.ibm.com/docs/codeengine?topic=codeengine-secretsecret-create-cli).



* Specify the username key with the value of user that is listed in the details of the service credentials in the Event Streams service instance. For the Event Streams service instance, this value is token. This key is required for authentication between the Code Engine Kafka event subscription and the Kafka message broker.
* Specify the password key with the value of apikey that is listed in the details of the service credentials in the Event Streams service instance. This key is required for the sender sample, and to enable communications between the Code Engine Kafka event subscription and the Kafka message broker.

ibmcloud ce secret create --name kafka-subscription-secret --from-literal password=<value_of_apikey> --from-literal username=<value_of_user>

For example,

ibmcloud ce secret create --name kafka-subscription-secret --from-literal password=abcdeH9tu3qE5Sn8VbJfcDEWtjR_l0iPisB3abcdefgh --from-literal username=token



2. Create the kafka-sender-app with the following information.



* Specify the --image option to reference the icr.io/codeengine/kafka-sender container image. This image is built from sender.go, which is available from the [Samples for IBM Cloud Code Engine GitHub repo](https://github.com/IBM/CodeEngine/tree/main/kafka). This sample sender app requires the password credentials that are stored in your kafka-subscription-secret, and it requires the BROKERS environment variable.
* Specify the --env-from-secret option to reference the full secret, kafka-subscription-secret, which contains the password credentials.
For Summary, review the settings for your Periodic timer event subscription and make changes if needed. When ready, click Create to create the Periodic timer (cron) subscription.



5. Now that your Periodic timer (cron) subscription is created, go to the Event subscriptions page to [view a listing of defined subscriptions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-subscribe-cronview-eventing-cron-app-ui).
6. To update a subscription, navigate to your Periodic timer (cron) subscription page. From the Event subscriptions page, click the name of the subscription that you want to update.
7. From your Periodic timer (cron) subscription page, let's change the data in the event message. From the Custom event data tab, change the event data to hello sunshine. Click Save to save your changes.
8. Because the myjob job references the sample codeengine application, which prints information to log files, you can view the logs. View the job logs for the myjob event consumer job and see that the event message is hello sunshine. See [Viewing job logs from the console](https://cloud.ibm.com/docs/codeengine?topic=codeengine-view-logsview-joblogs-ui).







 Subscribing to Periodic timer (cron) events for a job with the CLI 

Before you begin



* [Set up your Code Engine CLI environment](https://cloud.ibm.com/docs/codeengine?topic=codeengine-install-cli).
* [Create a project](https://cloud.ibm.com/docs/codeengine?topic=codeengine-manage-project).
* [Create a job](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-job-create). For example, create a job that is called myjob that uses the icr.io/codeengine/codeengine image.
The following table summarizes the options that are used with the sub cron create command in this example. For more information about the command and its options, see the [ibmcloud ce subscription cron create](https://cloud.ibm.com/docs/codeengine?topic=codeengine-clicli-subscription-cron-create) command.



Table 1. Command options

 Option Description 

 --name The name of the cron event source. 
 --destination-type The type of the destination, in this case, job. 
 --destination The name of a Code Engine job in the current project to receive the events from the event producer. 
 --schedule Schedule how often the event is triggered, in crontab format. For example, specify /2 * * * * (in string format) for every 2 minutes. By default, the cron event is triggered every minute and is set to the UTC time zone. To modify the time zone, use the --time-zone option. This value is optional. 



Tips for using the sub cron commands
: 

* The size of data for Periodic timer (cron) events is limited to a maximum of 4096 bytes. Thus, if you use the --data option or the --data-base64 option, you can send a maximum of 4096 bytes. For more information, see [Limits and quotas for Code Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits).
* Cron subscriptions use the UTC time zone by default. You can change the time zone by specifying the --time-zone option with the sub cron create or the sub cron update commands. For valid time zone values, see the [TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Note that if you create a subscription by using kubectl and do not specify a time zone, then the UTC time zone is assigned.