9.6.3.4 Asynchronous Job Example
The following examples shows how to submit asynchronous jobs with non-XML output and with XML output.
Non-XML Output
When submitting asynchronous jobs, for JSON, PNG and relational outputs, set the OUT_FMT
argument to NULL
when submitting the job. When fetching the job result, specify OUT_FMT
in the rqJobResult
call.
Issue a rqEval2
function call to submit an asynchronous job. In the
function. The PAR_LST
argument specifies submitting the job asynchronously
with the special control argument ore_async_flag
, capturing the images
rendered in the script with the special control argument ore_graphics_flag
.
The OUT_FMT
argument is NULL
. The
SCR_NAME
parameter specifies the user-defined R function stored with the
name RandomRedDots2
in the script repository.
The asynchronous call returns a job status URL in CLOB, you can call set long [length]
to get the full URL.
%script
set long 500
SELECT * FROM table(rqEval2(
par_lst => '{"ore_async_flag":true, "ore_graphics_flag":true, "ore_service_level":"LOW"}',
out_fmt => NULL,
scr_name => 'RandomRedDots2'));
The output is the following:
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
https://<host name>/oml/api/r-scripts/v1/jobs/<job id>
1 row selected.
Run a SELECT
statement that calls the rqJobStatus
function, which returns a resource URL containing the job ID when the job result is ready.
select * from rqJobStatus(
job_id => '<job id>');
The output is the following when the job is still pending.
NAME
----------------------------------------------------------------------
VALUE
----------------------------------------------------------------------
job is still running
1 row selected.
The output is the following when the job finishes.
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
https://<host name>/oml/api/r-scripts/v1/jobs/<job id>/result
1 row selected.
Run a SELECT
statement that calls the rqJobResult
function.
In the OUT_FMT
argument, the string 'PNG'
specifies to include both return value and images (titles and image bytes) in the result.
select * from rqJobResult(
job_id => '<job id>',
out_fmt => 'PNG'
);
The output is the following.
---------------------------
NAME ID VALUE IMAGE
1
89504E470D0A1A0A0000000D49484452000001E0000001E008060000007DD4BE950000200049444154789CECDD775853E
Note:
Here, only a portion of the output is shown. To determine the length of the output use the parameterset long [length]
.
XML Ouput
If XML output is expected from the asynchronous job, set the OUT_FMT
argument to 'XML'
when submitting the job and fetching the job result.
This example uses the script RandomRedDots2
created in the example
shown in the rqIndexEval2 Function topic.
Issue a rqEval2
function call to submit an asynchronous job. In the
function, the PAR_LST
argument specifies submitting the job asynchronously
with the special control argument ore_async_flag
and specifies using
LOW
service level with the special control argument
ore_service_level
.
The asynchronous call returns a job status URL in CLOB, you can call set long [length]
to get the full URL.
%script
set long 1000
SELECT * FROM table(rqEval2(
par_lst => '{"ore_async_flag":true, "ore_graphics_flag":true, "ore_service_level":"LOW"}',
out_fmt => 'XML',
scr_name => 'RandomRedDots2'));
The output is the following.
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
https://<host name>/oml/api/r-scripts/v1/jobs/<job id>
1 row selected.
Run a SELECT
statement that calls the rqJobStatus
function, which returns a resource URL containing the job id when the job result is ready.
select * from rqJobStatus(
job_id => '<job id>'
);
The output is the following when the job is still pending.
NAME
----------------------------------------------------------------------
VALUE
----------------------------------------------------------------------
job is still running
1 row selected.
The output is the following when the job result is ready.
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
https://<host name>/oml/api/r-scripts/v1/jobs/<job id>/result
1 row selected.
Run a SELECT
statement that calls the rqJobResult
function.
In the OUT_FMT
argument, the string 'XML'
specifies that the table returned contains a CLOB that is an XML string.
%script
set long 1000
select * from rqJobResult(
job_id => '<job id>',
out_fmt => 'XML'
);
The output is the following.
---------------------------
NAME VALUE
<root><R-data><frame_obj><ROW-frame_obj><id>1</id><val>0.01</val></ROW-frame_obj><ROW-frame_obj><id>2</id><val>0.02</val></ROW-frame_obj><ROW-frame_obj><id>3</id><val>0.03</val></ROW-frame_obj><ROW-frame_obj><id>4</id><val>0.04</val></ROW-frame_obj><ROW-frame_obj><id>5</id><val>0.05</val></ROW-frame_obj><ROW-frame_obj><id>6</id><val>0.06</val></ROW-frame_obj><ROW-frame_obj><id>7</id><val>0.07</val></ROW-frame_obj><ROW-frame_obj><id>8</id><val>0.08</val></ROW-frame_obj><ROW-frame_obj><id>9</id><val>0.09</val></ROW-frame_obj><ROW-frame_obj><id>10</id><val>0.1</val></ROW-frame_obj></frame_obj></R-data><images><image><img src="data:image/pngbase64"><![CDATA[iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAYAAAB91L6VAAAgAElEQVR4nOzdd3xTZfvH8U/StEmTtGUV2rKnCCjrARGZZcsegqgoKoKCqIAyHIgKylABUUFAZIuAAjIUZMkqZVVk7yl7tSTpSNP79wfqT7HjFJqctlzv16uvx6e5c873pKVXcs59rtuglFIIIYQQwqeMegcQQggh7kVSgIUQQggdSAEWQgghdCAFWAghhNCBFGAhhBBCB1KAhRBCCB1IARZCCCF0IAVYCCGE0IEUYCGEEEIHUoCFEEIIHUgBFkIIIXQgBVgIIYTQgRRgIYQQQgdSgIUQQggdSA
Parent topic: Asynchronous Jobs