Skip to content

Conversation

@Kcodess2807
Copy link
Contributor

📋 Summary
This PR adds comprehensive download control functionality to the GitHubDownloader Python API, enabling users to pause, resume, and cancel active downloads. This provides better control over long-running download operations and improves the overall user experience.

🔗 Related Issue
Closes #53 - Add download control functionality

🚀 Changes Made
✨ New Features

  • cancel_current_download() - Cancel active downloads immediately
  • Returns DownloadResult with CANCELLED status
  • Returns None if no active download
  • pause_current_download() - Pause active downloads
  • Async method that pauses current operation
  • Returns DownloadResult with PAUSED status
  • Returns None if no active download
  • resume_current_download() - Resume paused downloads
  • Async method that resumes paused operation
  • Returns DownloadResult with IN_PROGRESS status
  • Returns None if no paused download
  • 🔧 Technical Implementation
  • Leverages existing orchestrator control methods
  • Maintains thread-safe operations
  • Proper async/await patterns for pause/resume
  • Synchronous cancel for immediate termination

📝 Usage Examples
Basic Control Operations

from forklet import GitHubDownloader

downloader = GitHubDownloader()

# Start a download (in background)
download_task = asyncio.create_task(
    downloader.download("large-org", "huge-repo", "./downloads")
)

# Pause the download
result = await downloader.pause_current_download()
if result:
    print(f"Download paused: {result.status}")

# Resume the download
result = await downloader.resume_current_download()
if result:
    print(f"Download resumed: {result.status}")

# Cancel the download
result = downloader.cancel_current_download()
if result:
    print(f"Download cancelled: {result.status}")

Complete Workflow

# Workflow: start -> pause -> resume -> cancel
async def controlled_download():
    downloader = GitHubDownloader()
    
    # Start download in background
    download_task = asyncio.create_task(
        downloader.download("tensorflow", "tensorflow", "./tf")
    )
    
    # Wait a bit, then pause
    await asyncio.sleep(5)
    await downloader.pause_current_download()
    
    # Wait, then resume
    await asyncio.sleep(2)
    await downloader.resume_current_download()
    
    # Wait, then cancel
    await asyncio.sleep(5)
    downloader.cancel_current_download()

🧪 Testing
Test Coverage
✅ 11 comprehensive tests covering all control scenarios
✅ Success and edge cases for each operation
✅ Complete workflow testing (pause -> resume -> cancel)
✅ Async operation testing with proper mocking

Kcodess2807 added 4 commits October 6, 2025 23:32
- Add verbose parameter to GitHubDownloader constructor with default False
- Configure logger to use DEBUG level when verbose=True, INFO otherwise
- Pass verbose flag through to DownloadRequest for downstream logging
- Update logger output to stderr instead of stdout for proper separation
- Update constructor docstring with verbose parameter documentation

Closes AllDotPy#51
- Remove redundant if self.verbose checks before logger.debug calls
- Logger level filtering handles this automatically
- Remove unnecessary __main__ block from test file

Addresses maintainer feedback in PR review
- Add cancel_current_download() method for stopping active downloads
- Add pause_current_download() async method for pausing downloads
- Add resume_current_download() async method for resuming paused downloads
- Add comprehensive test suite for download control operations
- Support workflow: start -> pause -> resume -> cancel
- Return DownloadResult with appropriate status or None if no active download

Closes AllDotPy#53
Copy link
Contributor

@Einswilli Einswilli left a comment

Choose a reason for hiding this comment

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

Simple and clean!
Thanks!

@Einswilli Einswilli merged commit 8a2dd68 into AllDotPy:master Oct 6, 2025
2 checks passed
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.

Add Download Resume Functionality

2 participants