comparison xml/en/docs/http/ngx_http_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_http_js_module" 9 <module name="Module ngx_http_js_module"
10 link="/en/docs/http/ngx_http_js_module.html" 10 link="/en/docs/http/ngx_http_js_module.html"
11 lang="en" 11 lang="en"
12 rev="41"> 12 rev="42">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The <literal>ngx_http_js_module</literal> module is used to implement 17 The <literal>ngx_http_js_module</literal> module is used to implement
537 </para> 537 </para>
538 538
539 </directive> 539 </directive>
540 540
541 541
542 <directive name="js_periodic">
543 <syntax><value>function</value> |
544 <value>module.function</value>
545 [<literal>interval</literal>=<value>time</value>]
546 [<literal>jitter</literal>=<value>number</value>]
547 [<literal>worker_affinity</literal>=<value>mask</value>]</syntax>
548 <default/>
549 <context>location</context>
550 <context>if in location</context>
551 <context>limit_except</context>
552 <appeared-in>0.8.1</appeared-in>
553
554 <para>
555 Specifies a content handler to run at regular interval.
556 The handler receives a session object as its first argument,
557 it also has access to global objects such as
558 <link doc="../njs/reference.xml" id="ngx">ngx</link>.
559 </para>
560
561 <para>
562 The optional <literal>interval</literal> parameter
563 sets the interval between two consecutive runs,
564 by default, 5 seconds.
565 </para>
566
567 <para>
568 The optional <literal>jitter</literal> parameter sets the time within which
569 the location content handler will be randomly delayed,
570 by default, there is no delay.
571 </para>
572
573 <para>
574 By default, the <literal>js_handler</literal> is executed on worker process 0.
575 The optional <literal>worker_affinity</literal> parameter
576 allows specifying particular worker processes
577 where the location content handler should be executed.
578 Each worker process set is represented by a bitmask of allowed worker processes.
579 The <literal>all</literal> mask allows the handler to be executed
580 in all worker processes.
581 </para>
582
583 <para>
584 Example:
585 <example>
586 example.conf:
587
588 location @periodics {
589 # to be run at 1 minute intervals in worker process 0
590 js_periodic main.handler interval=60s;
591
592 # to be run at 1 minute intervals in all worker processes
593 js_periodic main.handler interval=60s worker_affinity=all;
594
595 # to be run at 1 minute intervals in worker processes 1 and 3
596 js_periodic main.handler interval=60s worker_affinity=0101;
597
598 resolver 10.0.0.1;
599 js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
600 }
601
602 example.js:
603
604 async function handler(s) {
605 let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
606 let body = async reply.text();
607
608 ngx.log(ngx.INFO, body);
609 }
610 </example>
611 </para>
612
613 </directive>
614
615
542 <directive name="js_preload_object"> 616 <directive name="js_preload_object">
543 <syntax><value>name.json</value> | 617 <syntax><value>name.json</value> |
544 <value>name</value> from <value>file.json</value></syntax> 618 <value>name</value> from <value>file.json</value></syntax>
545 <default/> 619 <default/>
546 <context>http</context> 620 <context>http</context>
657 The optional <literal>evict</literal> parameter removes the oldest 731 The optional <literal>evict</literal> parameter removes the oldest
658 key-value pair when the zone storage is exhausted. 732 key-value pair when the zone storage is exhausted.
659 </para> 733 </para>
660 734
661 <para> 735 <para>
662 Examples: 736 Example:
663 <example> 737 <example>
664 example.conf: 738 example.conf:
665 # Creates a 1Mb dictionary with string values, 739 # Creates a 1Mb dictionary with string values,
666 # removes key-value pairs after 60 seconds of inactivity: 740 # removes key-value pairs after 60 seconds of inactivity:
667 js_shared_dict_zone zone=foo:1M timeout=60s; 741 js_shared_dict_zone zone=foo:1M timeout=60s;