Queued NodeJS Server-Side Script and exception throwing


#1

NodeJS Queued Server-Side Script succeeds even on throwing an exception.

To check if I missed something I simply created a NodeJS Server-Side Script with the following code:

throw new Error('Something went wrong');

If I call the Endpoint with any method but without queueing the script, the server responds with error 500 and the script execution stops immediately.

If I call the Endpoint with any method but with queueing the script and then let the worker execute it from the queue, the script seems to stop BUT the job succeeds and disappears from the queue. This is bad because I need to take care of failed jobs (retrying later, check whats wrong etc.)

I tested this with V8js as script type and this works as expected (stops execution of the script, don’t deletes it from the queue, increasing attempts by 1 etc.) with and without queuing.

Because of a lot of async stuff, I cannot use V8js here and I am in need of NodeJS.

Any suggestions on that?

I just digged through some DF code and added the following lines to…

vendor/dreamfactory/df-script/src/Components/ScriptHandler.php

…so it console logs the whole $result array of the script.

$deb = print_r($result, true);
Log::info("Script '$identifier' result:" . PHP_EOL . $deb . PHP_EOL);

This is the result:

Without queueing the script

Array
(
    [request] => Array
        (
            [api_version] => 2.0
            [method] => POST
            [parameters] => Array
                (
                )

            [headers] => Array
                (
                    [authorization] => 
                    [host] => mobapi.fitisfit.de:8282
                    [connection] => keep-alive
                    [content-length] => 0
                    [accept] => application/json
                    [x-dreamfactory-api-key] => *
                    [cache-control] => no-cache
                    [origin] => chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
                    [user-agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
                    [postman-token] => 1f75505c-8e24-bb12-a265-d0e2ca9923a7
                    [accept-encoding] => gzip, deflate
                    [accept-language] => de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
                )

            [payload] => Array
                (
                )

            [content] => 
            [content_type] => 
        )

    [response] => Array
        (
            [content] => 
            [content_type] => 
            [status_code] => 200
        )

    [resource] => 
    [__tag__] => exposed_event
    [script_result] => Array
        (
            [error] => Something went wrong
        )

    [exception] => Array
        (
            [message] => Something went wrong
        )

)

With queueing the script

Array
(
    [resource] => 
    [request] => Array
        (
            [api_version] => 2.0
            [method] => POST
            [parameters] => Array
                (
                )

            [headers] => Array
                (
                    [authorization] => 
                    [host] => mobapi.fitisfit.de:8282
                    [connection] => keep-alive
                    [content-length] => 0
                    [accept] => application/json
                    [x-dreamfactory-api-key] => *
                    [cache-control] => no-cache
                    [origin] => chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
                    [user-agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
                    [postman-token] => 629cf369-32f1-bed1-8d0b-6bef1ae27535
                    [accept-encoding] => gzip, deflate
                    [accept-language] => de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
                )

            [payload] => Array
                (
                )

            [content] => 
            [content_type] => 
        )

    [__tag__] => exposed_event
)

This whole bit of data is missing if the Script gets executed via queue instead of directly on API call.
It seems that this need’s to be there for the queue worker to recognize that something is wrong and to fail the script.

        (
            [error] => Something went wrong
        )

    [exception] => Array
        (
            [message] => Something went wrong
        )

#2

@benbusse

Sorry for tagging you, but is there any solution for that?

If this is a bug, there might be interest to fix this in next releases.


#3

An engineer is investigating this. If there’s a bug here, we’ll fix it in the next sprint.


#4

Thanks :slight_smile:

Here is the Github issue