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

Improve TaskClient, BatchClient and associated types #1825

Merged
merged 63 commits into from
Apr 1, 2025

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Jan 13, 2025

Pull Request

What does this PR do?

  • remove classes Batch, EnqueuedTask and Task
    • these had no other functionality other than to re-create their *Object equivalent objects, that come from the API responses, for the most part with the same exact properties and values
    • some of them converted date strings to Date objects, but this functionality is also being removed, because:
      • most users don't use these properties, so for them it's just extra useless processing
      • maybe users want to use a different date object, like the upcoming Temporal API, or Luxon or any other
  • improve, fix, adjust and document types, with the help of meilisearch Rust source code
    • rename type EnqueuedTaskObject to EnqueuedTask
      • remove canceledBy property as it doesn't exist
      • indexUid property cannot be undefined but can be null
    • rename type BatchObject to Batch, adjust properties
    • rename type TaskObject to Task, adjust properties
      • for instance Task.details had quite a few properties missing, like pagination, now it's reusing the Settings type, so we don't repeat ourselves
  • rework and document TaskClient
    • refactor waitForTask, now it uses setTimeout for timeout instead of inaccurate expensive date calculations
    • can now accept task uid number or an EnqueuedTask object as parameter
    • waitForTasks can now accept an iterable or an asynchronous iterable instead of just an array as parameter
    • new method waitForTasksIter, which is an asynchronous generator, that lazily awaits the tasks
  • every method that returned a Promise<EnqueuedTask> now instead returns an EnqueuedTaskPromise
    • this is a Promise<EnqueuedTask> with an extra method waitTask, that first gets the EnqueuedTask and then internally calls TaskClient.waitForTask on it to return a Promise<Task>, avoiding quite a bit of boilerplate
  • new property on Config: defaultWaitOptions - used to set the default wait options for TaskClient
  • reduce interval for waiting tasks in tests, thus making tests complete often in under 2 minutes
  • new error: MeiliSearchTaskTimeOutError; thrown when waiting for a task times out via waitForTask and its derivatives

Caution

  • TaskClient is no longer exported, use it through Meilisearch or Index instead, on both available as tasks property
    • this brings it in line with BatchClient which isn't exported in the index file
  • Batch class is only a type now
  • EnqueuedTask class is only a type now
  • Task class is only a type now
  • any property on the 3 items above that was a Date before is now a string
    • conversion to Date is left to the user (new Date(str))
  • renamed MeiliSearchTimeOutError -> MeiliSearchRequestTimeOutError

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@flevi29 flevi29 added enhancement New feature or request breaking-change The related changes are breaking for the users labels Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.02%. Comparing base (5c418fb) to head (68c4afd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   99.17%   99.02%   -0.15%     
==========================================
  Files          16       18       +2     
  Lines        1574     1435     -139     
  Branches      348      303      -45     
==========================================
- Hits         1561     1421     -140     
- Misses         13       14       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flevi29 flevi29 added the bug Something isn't working label Jan 15, 2025
@flevi29 flevi29 changed the title Improve TaskClient, BatchClient, associated types, and settings types Improve TaskClient, BatchClient and associated types Jan 28, 2025
@flevi29 flevi29 marked this pull request as ready for review January 30, 2025 08:10
@flevi29 flevi29 mentioned this pull request Feb 27, 2025
@flevi29 flevi29 linked an issue Mar 2, 2025 that may be closed by this pull request
meili-bors bot added a commit that referenced this pull request Mar 8, 2025
1848: Remove hint about bad Meilisearch version r=Strift a=flevi29

# Pull Request

## What does this PR do?
- removes added warnings for potential bad Meilisearch version
  - there are many more places these should be added otherwise, but that would be a lot of trouble to maintain and counter productive, so let's instead remove the outliers
  - it would also make my life easier with the upcoming #1825 

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: F. Levi <[email protected]>
Co-authored-by: Laurent Cazanove <[email protected]>
@flevi29 flevi29 linked an issue Mar 17, 2025 that may be closed by this pull request
@Strift Strift requested a review from Copilot April 1, 2025 08:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reworks task and batch handling by removing redundant classes, renaming types to match API responses, and refactoring task waiting logic. Key changes include the removal of legacy task classes, an updated TaskClient using AbortController for timeouts, and revised type definitions across the codebase.

Reviewed Changes

Copilot reviewed 65 out of 65 changed files in this pull request and generated 1 comment.

File Description
src/types/types.ts Removed redundant imports and adjusted type properties (e.g. Dates to strings)
src/task.ts Refactored TaskClient methods for waiting tasks and integrated AbortController for timeouts
src/meilisearch.ts Updated usage of TaskClient and BatchClient to reflect new type definitions and methods
Other files (token, batch, errors, etc.) Updated, migrated, or removed legacy types and classes to align with new API responses

Copy link
Collaborator

@Strift Strift left a comment

Choose a reason for hiding this comment

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

LGTM 🙌

Awesome stuff, this will make the codebase much cleaner

@Strift Strift merged commit 780e469 into meilisearch:main Apr 1, 2025
7 checks passed
@flevi29 flevi29 deleted the improve-task-batch branch April 1, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users bug Something isn't working enhancement New feature or request maintenance Issue about maintenance (CI, tests, refacto...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Batches typing issues
2 participants