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

Task Status refactorings #556

Merged
merged 5 commits into from
Jul 25, 2024
Merged

Task Status refactorings #556

merged 5 commits into from
Jul 25, 2024

Conversation

Nukesor
Copy link
Owner

@Nukesor Nukesor commented Jul 23, 2024

Previously, the Task struct had lots of runtime related fields such as

  • enqueue_at: When a task should be enqueued.
  • enqueued_at: When a task has been enqueued.
  • start: When a task was started.
  • end: When a task finished.
  • result: The outcome of a task.

The problem with these was that all of them only made sense when the
task was in a specific state.
E.g. enqueue_at was only necessary when a task was Stashed,
start only made sense when a task was at least started, etc.

Whenever the state of a task changed, those invariants needed to be
enforced, which was prone to error as it was really easy to just forget
about something.

The new design takes all of those fields and moves them into the
TaskStatus enum as struct variants.

This made the code slightly more verbose, but significantly more robust.

@Nukesor Nukesor self-assigned this Jul 23, 2024
Nukesor added 3 commits July 23, 2024 14:54
Since we're fully breaking backwards compatibility anyway, we can take
the opportunity and clean up backwards compatibility related code.
Previously, the `Task` struct had lots of runtime related fields such as
- `enqueue_at`: When a task should be enqueued.
- `enqueued_at`: When a task has been enqueued.
- `start`: When a task was started.
- `end`: When a task finished.
- `result`: The outcome of a task.

The problem with these was that all of them only made sense when the
task was in a specific state.
E.g. `enqueue_at` was only necessary when a task was `Queued`,
`start` only made sense when a task was at least started, etc.

Whenever the state of a task changed, those invariants needed to be
enforced, which was prone to error as it was really easy to just forget
about something.

The new design moves all of those fields and moves them into the
`TaskStatus` enum as struct variants.

This made the code slightly more complex, but significantly more robust.
@Nukesor Nukesor force-pushed the status_refactorings branch from e577bc7 to 57101a5 Compare July 23, 2024 12:54
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

Attention: Patch coverage is 73.39056% with 62 lines in your changes missing coverage. Please review.

Project coverage is 79.23%. Comparing base (31878c4) to head (1ce4e1f).

Files Patch % Lines
pueue/src/daemon/process_handler/finish.rs 52.17% 11 Missing ⚠️
pueue/src/client/query/mod.rs 27.27% 8 Missing ⚠️
pueue/src/daemon/task_handler.rs 42.85% 8 Missing ⚠️
pueue/src/client/commands/wait.rs 50.00% 7 Missing ⚠️
pueue/src/daemon/callbacks.rs 0.00% 5 Missing ⚠️
pueue/src/daemon/process_handler/start.rs 61.53% 5 Missing ⚠️
pueue/src/daemon/process_handler/pause.rs 66.66% 4 Missing ⚠️
pueue/src/daemon/process_handler/spawn.rs 78.94% 4 Missing ⚠️
pueue/src/client/commands/restart.rs 60.00% 2 Missing ⚠️
pueue/src/client/display/log/mod.rs 66.66% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #556      +/-   ##
==========================================
- Coverage   79.49%   79.23%   -0.26%     
==========================================
  Files          75       75              
  Lines        5573     5653      +80     
==========================================
+ Hits         4430     4479      +49     
- Misses       1143     1174      +31     

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

@Nukesor Nukesor changed the title Status refactorings Task Status refactorings Jul 23, 2024
Copy link

github-actions bot commented Jul 23, 2024

Test Results

  3 files  ±0   19 suites   - 3   3m 4s ⏱️ ±0s
152 tests  - 2  152 ✅  - 2  0 💤 ±0  0 ❌ ±0 
322 runs   - 6  322 ✅  - 6  0 💤 ±0  0 ❌ ±0 

Results for commit 1ce4e1f. ± Comparison against base commit 31878c4.

This pull request removes 2 tests.
pueue-lib::message_backward_compatibility ‑ test_deserialize_new_message
pueue-lib::message_backward_compatibility ‑ test_deserialize_old_message

♻️ This comment has been updated with latest results.

@Nukesor Nukesor merged commit 960ed8f into main Jul 25, 2024
18 of 19 checks passed
@Nukesor Nukesor deleted the status_refactorings branch July 25, 2024 14:46
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.

1 participant