Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #download_with_index and #download_chunk methods to blob instances #41297

Closed

Conversation

psoldier
Copy link

@psoldier psoldier commented Feb 1, 2021

Add #download_with_index and #download_chunk methods to blob instances
If you need to download files by chunks, you could send a block to the download method.
However, if for some reason the execution of this block failed, there was no way to resume the processing from the last successfully processed chunk.

To take advantage of those previous chunks, it was necessary to re-implement the reading of files by chunks, using the download_chunk method, keeping a record of the execution point and updating offsets (something like a local pagination of chunks)

With the download_with_index method we will receive the chunk and (optionally) the current index in each block.
In case of failures, you only need to restart the execution with the index

a_tb_file.download_with_index(last_successfully_processed_chunk_index) do |chunk, index|
  # ...
  last_successfully_processed_chunk_index = index
end

If you need to download files by chunks, you could send a block to the download method.
However, if for some reason the execution of this block failed, there was no way to resume the processing from the last successfully processed chunk.

To take advantage of those previous chunks, it was necessary to re-implement the reading of files by chunks, using the `download_chunk` method, keeping a record of the execution point and updating offsets (something like a local pagination of chunks)

With the `download_with_index` method we will receive the chunk and (optionally) the current index in each block.
In case of failures, you only need to restart the execution with the index

```ruby
    a_tb_file.download_with_index(last_successfully_processed_chunk_index) do |chunk, index|
      # ...
      last_successfully_processed_chunk_index = index
    end
```
If you need to download files by chunks, you could send a block to the download method.
However, if for some reason the execution of this block failed, there was no way to resume the processing from the last successfully processed chunk.

To take advantage of those previous chunks, it was necessary to re-implement the reading of files by chunks, using the `download_chunk` method, keeping a record of the execution point and updating offsets (something like a local pagination of chunks)

With the `download_with_index` method we will receive the chunk and (optionally) the current index in each block.
In case of failures, you only need to restart the execution with the index

```ruby
  a_tb_file.download_with_index(last_successfully_processed_chunk_index) do |chunk, index|
    # ...
    last_successfully_processed_chunk_index = index
  end
```

Fix #download_chunk for blob instances was missing
@psoldier psoldier changed the title Active storage add dowload with index Add #download_with_index and #download_chunk methods to blob instances Feb 1, 2021
@rails-bot
Copy link

rails-bot bot commented May 14, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label May 14, 2021
@rails-bot rails-bot bot closed this May 22, 2021
@zzak zzak reopened this May 22, 2021
@rails-bot rails-bot bot removed the stale label May 22, 2021
@zzak
Copy link
Member

zzak commented May 22, 2021

🦄

@rails-bot
Copy link

rails-bot bot commented Aug 20, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Aug 20, 2021
@rails-bot rails-bot bot closed this Aug 27, 2021
@psoldier
Copy link
Author

I still think this is an interesting feature to have by default in active storage :)
@santib @zzak

@psoldier
Copy link
Author

psoldier commented Nov 4, 2022

Add #download_with_index and #download_chunk methods to blob instances

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants