comparison xml/en/docs/stream/ngx_stream_js_module.xml @ 3008:4470b2bff7b7

Documented the js_periodic directive.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 12 Sep 2023 21:32:42 +0100
parents 3184864bbb3f
children 55d49eb065ac
comparison
equal deleted inserted replaced
3007:3184864bbb3f 3008:4470b2bff7b7
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> 7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
8 8
9 <module name="Module ngx_stream_js_module" 9 <module name="Module ngx_stream_js_module"
10 link="/en/docs/stream/ngx_stream_js_module.html" 10 link="/en/docs/stream/ngx_stream_js_module.html"
11 lang="en" 11 lang="en"
12 rev="39"> 12 rev="41">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The <literal>ngx_stream_js_module</literal> module is used to implement 17 The <literal>ngx_stream_js_module</literal> module is used to implement
451 <note> 451 <note>
452 The directive can be specified on the 452 The directive can be specified on the
453 <literal>server</literal> level 453 <literal>server</literal> level
454 since <link doc="../njs/changes.xml" id="njs0.7.7">0.7.7</link>. 454 since <link doc="../njs/changes.xml" id="njs0.7.7">0.7.7</link>.
455 </note> 455 </note>
456 </para>
457
458 </directive>
459
460
461 <directive name="js_periodic">
462 <syntax><value>function</value> |
463 <value>module.function</value>
464 [<literal>interval</literal>=<value>time</value>]
465 [<literal>jitter</literal>=<value>number</value>]
466 [<literal>worker_affinity</literal>=<value>mask</value>]</syntax>
467 <default/>
468 <context>server</context>
469 <appeared-in>0.8.1</appeared-in>
470
471 <para>
472 Specifies a content handler to run at regular interval.
473 The handler receives a session object as its first argument,
474 it also has access to global objects such as
475 <link doc="../njs/reference.xml" id="ngx">ngx</link>.
476 </para>
477
478 <para>
479 The optional <literal>interval</literal> parameter
480 sets the interval between two consecutive runs,
481 by default, 5 seconds.
482 </para>
483
484 <para>
485 The optional <literal>jitter</literal> parameter sets the time within which
486 the location content handler will be randomly delayed,
487 by default, there is no delay.
488 </para>
489
490 <para>
491 By default, the <literal>js_handler</literal> is executed on worker process 0.
492 The optional <literal>worker_affinity</literal> parameter
493 allows specifying particular worker processes
494 where the location content handler should be executed.
495 Each worker process set is represented by a bitmask of allowed worker processes.
496 The <literal>all</literal> mask allows the handler to be executed
497 in all worker processes.
498 </para>
499
500 <para>
501 Example:
502 <example>
503 example.conf:
504
505 location @periodics {
506 # to be run at 1 minute intervals in worker process 0
507 js_periodic main.handler interval=60s;
508
509 # to be run at 1 minute intervals in all worker processes
510 js_periodic main.handler interval=60s worker_affinity=all;
511
512 # to be run at 1 minute intervals in worker processes 1 and 3
513 js_periodic main.handler interval=60s worker_affinity=0101;
514
515 resolver 10.0.0.1;
516 js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
517 }
518
519 example.js:
520
521 async function handler(s) {
522 let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
523 let body = async reply.text();
524
525 ngx.log(ngx.INFO, body);
526 }
527 </example>
456 </para> 528 </para>
457 529
458 </directive> 530 </directive>
459 531
460 532
642 The optional <literal>evict</literal> parameter removes the oldest 714 The optional <literal>evict</literal> parameter removes the oldest
643 key-value pair when the zone storage is exhausted. 715 key-value pair when the zone storage is exhausted.
644 </para> 716 </para>
645 717
646 <para> 718 <para>
647 Examples: 719 Example:
648 <example> 720 <example>
649 example.conf: 721 example.conf:
650 # Creates a 1Mb dictionary with string values, 722 # Creates a 1Mb dictionary with string values,
651 # removes key-value pairs after 60 seconds of inactivity: 723 # removes key-value pairs after 60 seconds of inactivity:
652 js_shared_dict_zone zone=foo:1M timeout=60s; 724 js_shared_dict_zone zone=foo:1M timeout=60s;