]> git.kaiwu.me - njs.git/commit
Modules: introduced js_periodic directive.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 22 Aug 2023 18:13:09 +0000 (11:13 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 22 Aug 2023 18:13:09 +0000 (11:13 -0700)
commitb14fec5f51b2299c8b4be5ab7bda47881aa848b4
treec8002d60465f78f9ee39f15f6c8310bb53f6f37a
parent0ee018404f580c889b52802d9c04d54508606450
Modules: introduced js_periodic directive.

The directive specifies a JS handler to run at regular intervals. The JS
handler will be executed in each worker process. The handler receives no
arguments. It has access to ngx and other global objects.

example.conf:
    location @periodics {
        # Specifies a JS handler to be run at 1 minute intervals
        js_periodic main.handler interval=60s jitter=5s;

        resolver 10.0.0.1;
        js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
    }

example.js:
    async function handler() {
        if (ngx.worker_id != 0) {
            /* using ngx.worker_id to run handler only in one worker. */
            return;
        }

        let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
        let body = async reply.text();

        ngx.log(ngx.INFO, body);
    }

This closes #660 issue on Github.
nginx/ngx_http_js_module.c
nginx/ngx_js.h
nginx/ngx_stream_js_module.c
nginx/t/js_periodic.t [new file with mode: 0644]
nginx/t/stream_js_periodic.t [new file with mode: 0644]