Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timers edit #2889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions content/eventing/eventing-Terminologies.dita
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,5 @@
code implementing the Function, all processing checkpoints, and other artifacts in the
metadata provider are purged. Before deleting, make sure you have undeployed the Function.
</section>
<section id="section_q23_vfz_w2b">
<title>Timers</title>
<p>Timers provide execution of code at a preconfigured clock time or after a specified number
of seconds. Using timers, you can write a simple JavaScript Function handler code to delay
or trigger the execution of a Function at specific wall-clock time events. Timers allow
archiving of expired documents at a preconfigured clock time. </p>
</section>
</body>
</topic>
8 changes: 3 additions & 5 deletions content/eventing/eventing-adding-function.dita
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<entry dir="ltr">Source Bucket</entry>
<entry>
<p dir="ltr">The name of a bucket currently defined on the cluster. </p>
<p dir="ltr">For more information on Source Bucket, refer to <xref
href="../clustersetup/create-bucket.dita#topic_fym_kmn_vs"/>.</p>
</entry>
</row>
<row>
Expand Down Expand Up @@ -96,9 +94,9 @@
<li>Click <b>Deploy</b>. This displays the <b>Confirm Deploy Function</b> dialog. The Feed
Boundary determines whether documents previously in existence needs to be included in the
Function's activities: the options are <b>Everything</b> and <b>From now</b>. The
<b>Everything</b> option invokes a Function on all the data present in the cluster. The
<b>From now</b> option invokes a Function during future instances of data mutation, post
Function deployment. </li>
<b>Everything</b> option invokes a Function on all data mutations. The <b>From now</b>
option invokes a Function during future instances of data mutation, post Function
deployment. </li>
<li>Click <b>Deploy</b> Function. This deploys the Function and returns you to the main
Eventing screen. The display indicates that the Function is now deployed and running. From
this point, your defined Function will run, first, on all existing documents; and
Expand Down
4 changes: 4 additions & 0 deletions content/eventing/eventing-api.dita
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<shortdesc> The Functions REST API, available by default at port 8096, provides the methods available to work with Couchbase
Functions. </shortdesc>
<body>
<p>
<note>The Functions REST API is a Beta feature intended for development purposes only, do not
use them in production; no Enterprise Support is provided for Beta features. </note>
</p>
<section id="section_kzm_vyy_m2b">
<p>
<table frame="all" rowsep="1" colsep="1" id="table_z5x_vyy_m2b">
Expand Down
109 changes: 0 additions & 109 deletions content/eventing/eventing-examples.dita
Original file line number Diff line number Diff line change
Expand Up @@ -374,115 +374,6 @@ function OnDelete(meta) {
<p/></li>
</ol>
</section>
<section id="section_wml_hfy_w2b"><title>Example 4</title><p dir="ltr"><b>Goal</b>: When a
document in an existing bucket is about to expire, a new document is created in a newly
created bucket. </p><b><i>Implementation</i></b>: Write an OnUpdate handler, which runs
whenever a document is created or mutated. The handler calls a timer routine, which executes a
callback function, two minutes prior to any document’s established expiration. This function
retrieves a specified value from the document, and stores it in a document of the same name,
in a specified target bucket. The original document in the source bucket is not changed..
<p>For this example, the buckets created such as source, target, and metadata buckets, are
used. A new document is created within the source bucket, and this document has its
expiration — or Time To Live (TTL) — set to occur ten minutes after the document's creation.
</p><p>Python script for this Example is provided for reference. Using the Couchbase SDK,
you can create or modify the document expiration. In this example, the Couchbase SDK Python
client creates a document and sets the document's expiration.
</p><codeblock>from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
import time
cluster = Cluster('couchbase://localhost: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*60)</codeblock><p>The
script imports a Couchbase cluster object, and authenticates against it, using (for
demonstration purposes) the Full Administrator username and password (the cluster is assumed
to be accessible on localhost). The script then opens the existing source bucket, and
inserts a new document, named <b><i>SampleDocument2</i></b>, whose body is <b><i>{'a_key':
'a_value'}</i></b>. </p><p>For information on installing the Couchbase Python SDK, refer
to <xref href="../sdk/java/start-using-sdk.dita#topic_vpj_dh5_xv">Start Using the
SDK</xref>. For information on using the Couchbase Python SDK to establish
bucket-expiration, refer to <xref
href="../sdk/dotnet/document-operations.dita#document-kv-operations-dotnet">Document
Operations</xref>. </p><p><b>Procedure</b></p><p dir="ltr">Proceed as follows:</p><ol
id="ol_chx_3fy_w2b">
<li>Install the Couchbase SDK Python client and from the appropriate folder, start
Python.<codeblock>./python</codeblock></li>
<li>On the Python prompt, enter the provided
code.<codeblock>>>> from couchbase.cluster import Cluster
>>> from couchbase.cluster import PasswordAuthenticator
>>> import time
>>> cluster = Cluster('couchbase://localhost:8091')
>>> authenticator = PasswordAuthenticator('Administrator', 'password')
>>> cluster.authenticate(authenticator)
>>> cb = cluster.open_bucket('source')
>>> cb.upsert('SampleDocument2', {'a_key': 'a_value'})
OperationResult&lt;rc=0x0, key='SampleDocument2', cas=0x1519ec8cdee90000>
>>> cb.touch('SampleDocument2', ttl=10*60)
OperationResult&lt;rc=0x0, key='SampleDocument2', cas=0x1519ec8e686c0000>
>>></codeblock></li>
<li>To verify bucket creation, access the <b>Buckets</b> screen from the <b>Couchbase Web
Console</b> and click the <b>Document</b> tab of the <b>Source</b> bucket. The new
document gets displayed. </li>
<li>[Optional Step] Click on a document's id to view the metadata information. </li>
<li>From the <b>Couchbase Web Console</b> > <b>Eventing </b>page, click <b>ADD FUNCTION</b>,
to add a new Function. The <b>ADD FUNCTION</b> dialog appears.</li>
<li>In the <b>ADD FUNCTION</b> dialog, for individual Function elements provide the below
information:<ul id="ul_dtm_lgy_w2b">
<li>For the <b>Source Bucket</b> drop-down, select <b>source</b>. </li>
<li>For the <b>Metadata Bucket</b> drop-down, select <b>metadata</b>. </li>
<li>Enter <b>add_timer_before_expiry</b> as the name of the Function you are creating in
the <b>FunctionName</b> text-box. </li>
<li>Enter text <b>Function that adds timer before document expiry</b>, in the
<b>Description</b> text-box. </li>
<li>For the <b>Settings</b> option, use the default values. </li>
<li>For the <b>Bindings</b> option, add two bindings. For the first binding specify
<b>source</b> as the name of the bucket, and specify <b>src</b> as the associated
value. For the second binding, specify <b>target</b> as the name of the bucket, and
specify <b>tgt</b> as the associated value. </li>
</ul></li>
<li>After providing all the required information in the <b>ADD FUNCTION</b> dialog, click
<b>Next: Add Code</b>. The <b>add_timer_before_expiry</b> dialog appears. </li>
<li>The <b>add_timer_before_expiry</b> dialog initially contains a placeholder code block.
You will substitute your actual <b>add_timer_before_expiry code</b> in this block.
<p><image href="images/casacade_del_withcode.png" width="600" id="image_ghx_3fy_w2b"
/></p></li>
<li>Copy the following Function, and paste it in the placeholder code block of
<b>add_timer_before_expiry</b> dialog. <p dir="ltr"
/><codeblock>function OnUpdate(doc, meta) {
if (meta.expiration > 0 ) //do only for those documents that have a non-zero TTL
{
var expiry = new Date(meta.expiration);
// Compute 2 minutes from the TTL timestamp
var twoMinsPrior = new Date(expiry.setMinutes(expiry.getMinutes()-2));
var context = {docID : meta.id};
createTimer(DocTimerCallback, twoMinsPrior , meta.id, context);
log('Added Doc Timer to DocId:', meta.id);
}
}
function DocTimerCallback(context)
{
log('DocTimerCallback Executed for DocId:', String(context.docID));
tgt[context.docID] = "To Be Expired Key's Value is:" + JSON.stringify(src[context.docID]);
log('Doc Timer Executed for DocId', String(context.docID));
}</codeblock><p
dir="ltr">After pasting, the screen appears as displayed below:</p><p><image
href="images/casacade_del_withcode.png" width="600" id="image_ff1_gjy_w2b"/></p></li>
<li>Click <b>Save</b>. </li>
<li>To return to the Eventing screen, click <b>Eventing</b> tab. </li>
<li>From the <b>Eventing</b> screen, click <b>Deploy</b>. </li>
<li>In the <b>Confirm Deploy Function</b> dialog, select <b>Everything from the Feed
boundary</b> option. </li>
<li>Click <b>Deploy</b>. The function is deployed and starts running within a few seconds.
<p><image href="images/cascade_delete_buckets.png" width="600" id="image_jcw_ljy_w2b"
/></p><p dir="ltr">As a result, a new document — like the original, named
<b>SourceDocument2</b> — is created, with a value based on that of the original. After
two minutes has elapsed, check the documents within the source bucket: the original
<b>SourceDocument2</b> is no longer visible, having been removed at its defined
expiration-time.</p></li>
</ol></section>

</body>
</topic>
16 changes: 0 additions & 16 deletions content/eventing/eventing-faq.dita
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,6 @@
<p>We block one of the mutations alone and hand it over to the debugger session. The rest
of the mutations continue to be serviced by the event handler.</p>
</li>
<li>Are timers scalable? <p>Timers get automatically sharded across Eventing nodes and
therefore are elastically scalable. Due to sharding, triggering of timers at or after a
specified time interval is guaranteed. However, triggering of timers may either be on
the same node where the time was created, or on a different node. Relative ordering
between two specific timers cannot be maintained.</p></li>
<li>
<p>Can I use Debugger to debug timers? </p>
<p>Timers cannot be debugged using the Visual Debugger. </p>
</li>
<li>What happens when the Function handler code contains a timestamp in the past? <p>When a
Function handler code contains a timestamp in the past, upon a successful Function
deployment, the system executes the code in the next available time slot. </p></li>
<li>What is the Timer behavior post reboot? <p>During a boot operation, all clocks in the
cluster nodes get synchronized. Post-startup, cluster nodes get periodically
synchronized using clock synchronization tools such as Network Time Protocol (NTP).
</p></li>

</ul>

Expand Down
Loading