Skip to content

Conversation

@wiitt
Copy link
Collaborator

@wiitt wiitt commented Jan 24, 2025

Solves #31
This PR adds the way to handle files grater in size than 1Gb. It adds and utilizes a consumer that processes responses in chunks.

How to test
Download files of various types and sizes.

The code has been already tested with the following request parameters:

params = struct(...
    'deviceCode', 'ASLCORAS300KHZMAIN',...
    'dateFrom', '2025-01-08T00:00:00.000Z',...
    'dateTo', '2025-01-09T00:00:00.000Z',...
    'extension','dat'...
    ); 
params = struct(...
    'deviceCode', 'CMAPCYCLOPS01',...
    'dateFrom', '2008-10-07T18:50:00.000Z',...
    'dateTo', '2008-10-07T18:52:00.000Z',...
    'extension','mpg'...
    );
params = struct(...
    'deviceCode', 'VWPiez62473',...
    'dateFrom', '2012-11-11T00:00:00.000Z',...
    'dateTo', '2012-11-12T00:00:00.000Z',...
    'extension','dat'...
    );
params = struct(...
    'deviceCode', 'SF_2100_0075',...
    'dateFrom', '2009-07-02T00:00:00.000Z',...
    'dateTo', '2009-07-03T00:00:00.000Z',...
    'extension','dat'...
    );

@wiitt
Copy link
Collaborator Author

wiitt commented Jan 24, 2025

I wonder if the tests are supposed to be passed

@spencerwplovie
Copy link
Contributor

I wonder if the tests are supposed to be passed

I had a similar issue with the tests not passing initially in #26, but it looks like they ended up passing sometime before Ben merged the branch. If I remember correctly, I think he mentioned that the test suite needs to be refactored in some places. It looks like Isla, the previous scientific programmer co-op, was working on this in #10, but the PR was closed.


if nargin < 1
chunkSize = 2^29; % default value
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be handy to have a check when the user passes in a value for chunkSize to make sure it's less than the 2^30 bytes limit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not quite sure how to pass in a value for chunkSize. It's not a parameter, so would the user need to run chunkSize = int; on the command line before they run a data product order?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Checking the chunkSize value would be helpful. I'll add it.

As for how to set this parameter up, it is done when the class is initialized. At the moment when an instance of this class is created, a user can pass input argument to the class like

chunkSize = 2^29;
consumer = onc.ChunkedResponseConsumer(chunkSize);
response = request.send(uri, options, consumer);

I might need to add empty brackets to line 28 onc/+util/do_request.m where the consumer is initialized. Or, to spare people from guessing, I can make passing of the parameter explicit by doing it in the way it is done in the code snippet above.

end

methods (Access = protected)
function bufsize = start(obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably say function buffsize = start(obj)

@@ -0,0 +1,96 @@
classdef ChunkedResponseConsumer < matlab.net.http.io.GenericConsumer
%% ChunkedResponseConsumer Consumer with an option to control the size of
% chucks which a response is processed in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chunks (minor typo but it's worth fixing)

@wiitt
Copy link
Collaborator Author

wiitt commented Feb 10, 2025

Sorry that it took so long to get back to this PR because of dealing with other tasks

@wiitt
Copy link
Collaborator Author

wiitt commented Feb 10, 2025

Hmm, now the updated code doesn't pass checks even though the updates are minor
I'm checking it

@KristenMeyerONC
Copy link

Hmm, now the updated code doesn't pass checks even though the updates are minor I'm checking it

There was a deployment today that may have interfered with the checks.

@wiitt wiitt requested a review from spencerwplovie February 10, 2025 23:18
if showInfo, fprintf('\nRequesting URL:\n %s\n', fullUrl); end
tic
consumer = onc.ChunkedResponseConsumer;
chunckSize = 2^29; % half of the max response size that `send` can handle
Copy link
Contributor

@spencerwplovie spencerwplovie Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable should be called and passed in as chunkSize to be consistent

@wiitt wiitt requested a review from spencerwplovie February 11, 2025 17:57
@spencerwplovie spencerwplovie merged commit a2d8260 into main Feb 11, 2025
2 checks passed
@spencerwplovie spencerwplovie deleted the issue-29-api-fails-downloading-files-greater-than-1gb branch February 11, 2025 22:42
@wiitt wiitt assigned wiitt and unassigned wiitt Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants