Example 2 not create documents in target

Hi I used following demo link Example 2

I tried all mentioned steps but documents not created in target buckets and eventing debug show this message “Open the following URL to begin debugging. Waiting for mutation” is there any way to check eveneting script also log() statement not print any log on browser console . For ref. please check below screen-shots .

The log statement used in the handler code will be printed in application log.

For linux it will at the below said location
/opt/couchbase/var/lib/couchbase/data/@eventing/<function_name>.log

1 Like

@yogesh_0586 - Can you please create an alias for source bucket as well as shown in the below screenshot and retry ?

If you look at the handler code carefully we access source bucket to read data (See below). We need to create an alias whenever we access it.

tgt[docid] = “To Be Expired Key’s Value is:” + JSON.stringify(src[docid]);

Please try it and let us know if it helps.

I removed old eventing function and create a new with two new bindings as you mentioned but still it’s not create a documents in target buckets. :slightly_frowning_face:

@yogesh_0586 - Could you also create few more new docs on source bucket with 10mins expiry and wait for 8 mins (as we create docs on destination 2 mins before expiry) and see if docs get created on target bucket ?

Thanks for you reply, I inserted new documents with TTL 10 min. and wait for 8 mins. but still not created documents in target buckets, I also wait for 10 mins. even my source bucket documents was empty but target buckets don’t have any documents in log as mentioned path not generate specific error . For ref please check eventing code as below:

	{
		"appname": "add_timer_before_expiry",
		"id": 0,
		"depcfg": {
			"buckets": [{
				"alias": "tgt",
				"bucket_name": "target"
			}, {
				"alias": "src",
				"bucket_name": "source"
			}],
			"metadata_bucket": "metadata",
			"source_bucket": "source"
		},
		"appcode": "function OnUpdate(doc, meta) {\n  if (meta.expiration > 0 ) //do only for those documents that have a non-zero TTL\n  {\n    //have to x by 1000, as timestamp in secs; and for Date operations need in milli-secs\n    var expiry = new Date(meta.expiration*1000); \n    // Compute 2 minutes from the TTL timestamp        \n    var twoMinsPrior =  Math.round(expiry.setMinutes(expiry.getMinutes()-2)/1000); \n    log(\"A:\"+twoMinsPrior);\n    log(\"B:\"+meta.id)\n    docTimer(DocTimerCallback, meta.id, twoMinsPrior);  //create the docTimer\n    log('Added Doc Timer to DocId:', meta.id);\n  }\n}\n\nfunction DocTimerCallback(docid, expiry) {\n  log('DocTimerCallback Executed for DocId:', String(docid));\n  tgt[docid] = \"To Be Expired Key's Value is:\" + JSON.stringify(src[docid]);\n  log('Doc Timer Executed for DocId', String(docid));\n}",
		"settings": {
			"app_log_max_files": 10,
			"app_log_max_size": 10485760,
			"breakpad_on": true,
			"checkpoint_interval": 10000,
			"cleanup_timers": false,
			"cpp_worker_thread_count": 2,
			"curl_timeout": 500,
			"dcp_stream_boundary": "everything",
			"deadline_timeout": 3,
			"deployment_status": false,
			"description": "",
			"enable_recursive_mutation": false,
			"execution_timeout": 1,
			"fuzz_offset": 0,
			"lcb_inst_capacity": 5,
			"log_level": "TRACE",
			"processing_status": false,
			"skip_timer_threshold": 86400,
			"sock_batch_size": 100,
			"tick_duration": 60000,
			"timer_processing_tick_interval": 500,
			"vb_ownership_giveup_routine_count": 3,
			"vb_ownership_takeover_routine_count": 3,
			"worker_count": 3,
			"worker_queue_cap": 100000,
			"xattr_doc_timer_entry_prune_threshold": 100
		}
	}

This “DocTimerCallback” not called I think issue related to this line “docTimer(DocTimerCallback, meta.id, twoMinsPrior); //create the docTimer”

@yogesh_0586 - I imported the function that you have pasted above. It worked for me.

Let me list the steps I followed so that we are on the same page.

  1. Created 3 couchbase buckets metadata, source and target.
  2. Created a json file with your contents that you mentioned above.
  3. Imported the json file and deployed the function.
  4. Wait for the function status to turn deployed and running.
  5. Created the following python file and executed it. It created a single document on source bucket.
from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
import time
cluster = Cluster('couchbase://10.111.170.101:8091')
authenticator = PasswordAuthenticator('Administrator', 'password')
cluster.authenticate(authenticator)

cb = cluster.open_bucket('source')
cb.upsert('SampleDocument2', {'a_key': 'a_value'})
cb.touch('SampleDocument2', ttl=10*30)

After 3 mins there was doc on target bucket.

Thanks for your reply, I removed my previous eventing code and import from json also removed all buckets and created new three buckets ( source, target, meatadata ) and insert data in source bucket using python code.

And wait for 3 mins and finally expired documents created in target buckets :+1:

1 Like

There was a step to create the source bucket binding(step#4) that was missing in Example-2. Now the Doc has been updated.

@venkat Thanks for the update