Skip to content

Use njs.on('exit', () => {}) event for execute a fetch call #543

@tmm360

Description

@tmm360

I need to execute a fetch call after have finished a request, filtered with a njs body filter.
This call needs to pass the value of a variable that I've built with the filter, containing the amount of bytes passed with body.

I see that exists the njs.on(event, callback) method, so into the header filter I'm testing this code:

    njs.on('exit', () => {
        ngx.fetch('https://www.google.com/robots.txt')
            .then(reply => reply.text())
            .then(text => r.warn(text.substring(0, 10)));
    });

Anyway, instead of receive in logs the first chars of the robots file, I receive these errors:

2022/06/12 00:24:05 [notice] 1#1: signal 17 (SIGCHLD) received from 38
2022/06/12 00:24:05 [alert] 1#1: worker process 38 exited on signal 11
2022/06/12 00:24:05 [notice] 1#1: start worker process 55
2022/06/12 00:24:05 [notice] 1#1: signal 29 (SIGIO) received

Are asynchronous operation supported on this event? And if not, how could I perform this request? I'm not interested in result received by nginx, only that fetch is executed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions