Skip to content

Commit

Permalink
Workout enhancements (#1142)
Browse files Browse the repository at this point in the history
* chore(frontend): highlight image only when server key is validated

* feat(frontend): animate the application grid

* chore(services/importer): better error message for failed item for plex

* feat(frontend): add new btn for pausing workouts

* feat(frontend): start implementing pause timer

* feat(frontend): more changes for pausing timer

* feat(frontend): complete pausing rest timer

* refactor(frontend): change name of function

* fix(frontend): circular progress for exercise set timer

* feat: remove job to revise calendar events

* chore(frontend): add margin top to btn

* feat(backend): add job to delete all application cache

* feat(frontend): allow deploying job to delete all cache

* docs: update minio playground credentials

* docs: add info about converting local user to oidc

* docs: change image content

* docs: information about caching

* chore(frontend): change order of stuff

* refactor(frontend): use array map to display all background jobs

* refactor(frontend): inline button props

* feat(frontend): add stack

* build(frontend): add code highlight deps

* chore(frontend): move all css to root layout

* chore(frontend): add code highlight styles

* feat(frontend): display failed items in code block

* feat(frontend): more styles in import reports

* feat(migrations): add preference for prompt for rest timer

* feat(backend): add setting for prompt for rest timer

* feat(frontend): allow changing new user preference

* feat(frontend): add pro key validation

* refactor(backend): change name of function

* refactor(frontend): extract tasks to do after set is confirmed

* refactor(frontend): change order of function declaration

* feat(frontend): display timer button for new preference

* refactor(frontend): change order of declarations

* chore(backend): remove useless field

* feat(backend): allow storing rest timer started at

* feat(frontend): send new attribute to the backend

* feat(frontend): extract function to a hook

* feat(frontend): get tasks after rest timer over working

* feat(backend): remove useless attribute

* chore(models/media): change order of attributes

* refactor(backend): move stuff to inside function

* refactor(services/miscellaneous): remove stuff

* chore(frontend): fix typescript errors

* chore(backend): apply clippy lints

* feat(backend): deploy additional jobs

* refactor(backend): common function to call methods

* refactor(services/integration): change name of import

* refactor(services/integration): use fully qualified `Result`

* perf(frontend): load workout only when it is in view

* fix(frontend): better layout for notification settings

* feat(frontend): add hint on notification settings page

* ci: Run CI

* refactor(backend): do not inject dependencies one at a time

* ci: Run CI

* refactor(backend): extract env variable name

* refactor(backend): use better import

* refactor(backend): change imports

* chore(services/cache): remove basic cache after 5 days

* fix(frontend): reduce workout starter delay to 4 seconds

* feat(frontend): change color of timer when it is paused

* refactor(frontend): remove calls to dayjs when not required

* refactor(frontend): change order of attributes

* feat(frontend): change RPE modal presentation

* feat(frontend): change RPE modal presentation even more

* refactor(frontend): extract function

* fix(utils/dependent): use correct equality

* feat(migrations): make nulls not distinct for unique index

* feat(frontend): allow picking images using native technologies

* feat(frontend): allow picking images using native technologies

* fix(frontend): add accept types

* fix(frontend): allow confirming sets

* feat(migrations): make duration a normal column

* feat(utils/dependent): calculate workout duration manually

* feat(frontend): use native file button

* feat(frontend): synthetic changes when workout paused

* feat(migrations): add information about workout durations

* feat(backend): add durations support to the schema

* feat(utils/dependent): do not error out early if there are no durations

* feat(utils/dependent): add more validation

* feat(migrations): delete all application cache

* feat(migrations): add version to application cache

* ci: pass commit sha to env

* Revert "ci: pass commit sha to env"

This reverts commit 78e4cc4.

* feat(backend): respect cache version

* Revert "Revert "ci: pass commit sha to env""

This reverts commit 7df7327.

* ci: pass the entire sha to the env

* docs: add new required env variable

* feat(backend): put the commit sha in the application cache version

* feat(frontend): build workout durations correctly

* ci: Run CI

* chore(frontend): use correct dayjs lib duration

* feat(frontend): allow pausing workouts

* feat(frontend): confirming a set resumes the workout duration

* feat(frontend): disable finish button when workout paused

* chore(migrations): do not add durations to workouts without it

* feat(utils/dependent): calculate correct duration of the workout

* ci: Run CI

* feat(ts-utils): support for compact distance notation

* feat(frontend): display tooltip in analytics section

* chore: change name of env variable

* ci: Run CI

* refactor(frontend): remove useless extra component

* chore(frontend): remove fallback

* chore(frontend): change order of attributes

* feat(website): add description to the website

* chore(migrations): add all migrations into execute unprepared

* ci: Run CI

* fix(migrations): add if not exists

* ci: Run CI

* chore(gql): remove newline

* fix(services/statistics): do not group data if millenium requested

* refactor(backend): use default when possible

* chore(backend): do not return useless stuff from metadata search details

* chore(frontend): adapt to new gql schema

* refactor(frontend): change order of stuff

* chore(frontend): change order of params

* refactor(backend): use `Default::default()` wherever possible

* ci: Run CI

* ci: Run CI
  • Loading branch information
IgnisDa authored Dec 24, 2024
1 parent 69c7878 commit 5e1a32f
Show file tree
Hide file tree
Showing 93 changed files with 1,803 additions and 1,621 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ jobs:
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT"
- name: Extract rust toolchain
Expand Down Expand Up @@ -176,11 +177,12 @@ jobs:
locked: false
- name: Build
env:
UNKEY_API_ID: ${{ secrets.UNKEY_API_ID }}
APP_COMMIT_SHA: ${{ steps.build.outputs.sha }}
APP_VERSION: ${{ steps.build.outputs.version }}
DEFAULT_TMDB_ACCESS_TOKEN: ${{ secrets.DEFAULT_TMDB_ACCESS_TOKEN }}
DEFAULT_MAL_CLIENT_ID: ${{ secrets.DEFAULT_MAL_CLIENT_ID }}
TRAKT_CLIENT_ID: ${{ secrets.TRAKT_CLIENT_ID }}
UNKEY_API_ID: ${{ secrets.UNKEY_API_ID }}
DEFAULT_MAL_CLIENT_ID: ${{ secrets.DEFAULT_MAL_CLIENT_ID }}
DEFAULT_TMDB_ACCESS_TOKEN: ${{ secrets.DEFAULT_TMDB_ACCESS_TOKEN }}
run: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --release
- name: Upload build artifact
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[build.env]
passthrough = [
"APP_VERSION",
"DEFAULT_TMDB_ACCESS_TOKEN",
"DEFAULT_MAL_CLIENT_ID",
"TRAKT_CLIENT_ID",
"APP_COMMIT_SHA",
"UNKEY_API_ID",
"TRAKT_CLIENT_ID",
"DEFAULT_MAL_CLIENT_ID",
"DEFAULT_TMDB_ACCESS_TOKEN",
]

[build]
Expand Down
26 changes: 12 additions & 14 deletions apps/backend/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use axum::{
routing::{get, post, Router},
Extension,
};
use background_models::{
ApplicationJob, HpApplicationJob, LpApplicationJob,
MpApplicationJob,
};
use background_models::{ApplicationJob, HpApplicationJob, LpApplicationJob, MpApplicationJob};
use cache_service::CacheService;
use collection_resolver::{CollectionMutation, CollectionQuery};
use collection_service::CollectionService;
Expand Down Expand Up @@ -50,7 +47,6 @@ use user_service::UserService;

/// All the services that are used by the app
pub struct AppServices {
pub app_router: Router,
pub fitness_service: Arc<FitnessService>,
pub importer_service: Arc<ImporterService>,
pub exporter_service: Arc<ExporterService>,
Expand All @@ -68,7 +64,7 @@ pub async fn create_app_services(
lp_application_job: &MemoryStorage<LpApplicationJob>,
mp_application_job: &MemoryStorage<MpApplicationJob>,
hp_application_job: &MemoryStorage<HpApplicationJob>,
) -> AppServices {
) -> (Router, Arc<AppServices>) {
let oidc_client = create_oidc_client(&config).await;
let file_storage_service = Arc::new(FileStorageService::new(
s3_client,
Expand Down Expand Up @@ -159,15 +155,17 @@ pub async fn create_app_services(
))
.layer(cors);

AppServices {
(
app_router,
fitness_service,
importer_service,
exporter_service,
statistics_service,
integration_service,
miscellaneous_service,
}
Arc::new(AppServices {
fitness_service,
importer_service,
exporter_service,
statistics_service,
integration_service,
miscellaneous_service,
}),
)
}

async fn create_oidc_client(config: &config::AppConfig) -> Option<CoreClient> {
Expand Down
130 changes: 84 additions & 46 deletions apps/backend/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ use std::sync::Arc;
use apalis::prelude::*;
use background_models::{HpApplicationJob, LpApplicationJob, MpApplicationJob, ScheduledJob};
use common_utils::ryot_log;
use exporter_service::ExporterService;
use fitness_service::FitnessService;
use importer_service::ImporterService;
use integration_service::IntegrationService;
use miscellaneous_service::MiscellaneousService;
use statistics_service::StatisticsService;
use traits::TraceOk;

use crate::common::AppServices;

pub async fn run_background_jobs(
information: ScheduledJob,
misc_service: Data<Arc<MiscellaneousService>>,
app_services: Data<Arc<AppServices>>,
) -> Result<(), Error> {
ryot_log!(debug, "Running job at {:#?}", information.0);
misc_service.perform_background_jobs().await.trace_ok();
app_services
.miscellaneous_service
.perform_background_jobs()
.await
.trace_ok();
Ok(())
}

pub async fn run_frequent_jobs(
_information: ScheduledJob,
fitness_service: Data<Arc<FitnessService>>,
integration_service: Data<Arc<IntegrationService>>,
app_services: Data<Arc<AppServices>>,
) -> Result<(), Error> {
integration_service
app_services
.integration_service
.yank_integrations_data()
.await
.trace_ok();
fitness_service
app_services
.fitness_service
.process_users_scheduled_for_workout_revision()
.await
.trace_ok();
Expand All @@ -38,80 +39,105 @@ pub async fn run_frequent_jobs(

pub async fn perform_hp_application_job(
information: HpApplicationJob,
misc_service: Data<Arc<MiscellaneousService>>,
statistics_service: Data<Arc<StatisticsService>>,
integration_service: Data<Arc<IntegrationService>>,
app_services: Data<Arc<AppServices>>,
) -> Result<(), Error> {
ryot_log!(trace, "Started job {:?}", information);
let status = match information {
HpApplicationJob::SyncUserIntegrationsData(user_id) => {
integration_service
.yank_integrations_data_for_user(&user_id)
app_services
.integration_service
.sync_integrations_data_for_user(&user_id)
.await
}
HpApplicationJob::RecalculateUserActivitiesAndSummary(
user_id,
calculate_from_beginning,
) => {
statistics_service
app_services
.statistics_service
.calculate_user_activities_and_summary(&user_id, calculate_from_beginning)
.await
}
HpApplicationJob::ReviewPosted(event) => {
misc_service.handle_review_posted_event(event).await
app_services
.miscellaneous_service
.handle_review_posted_event(event)
.await
}
HpApplicationJob::BulkProgressUpdate(user_id, input) => {
misc_service.bulk_progress_update(user_id, input).await
app_services
.miscellaneous_service
.bulk_progress_update(user_id, input)
.await
}
};
status.map_err(|e| Error::Failed(Arc::new(e.message.into())))
}

pub async fn perform_mp_application_job(
information: MpApplicationJob,
misc_service: Data<Arc<MiscellaneousService>>,
integration_service: Data<Arc<IntegrationService>>,
importer_service: Data<Arc<ImporterService>>,
exporter_service: Data<Arc<ExporterService>>,
fitness_service: Data<Arc<FitnessService>>,
app_services: Data<Arc<AppServices>>,
) -> Result<(), Error> {
ryot_log!(trace, "Started job {:?}", information);
let status = match information {
MpApplicationJob::ImportFromExternalSource(user_id, input) => {
importer_service.perform_import(user_id, input).await
app_services
.importer_service
.perform_import(user_id, input)
.await
}
MpApplicationJob::ReviseUserWorkouts(user_id) => {
fitness_service.revise_user_workouts(user_id).await
app_services
.fitness_service
.revise_user_workouts(user_id)
.await
}
MpApplicationJob::UpdateMetadata(metadata_id) => {
misc_service
app_services
.miscellaneous_service
.update_metadata_and_notify_users(&metadata_id)
.await
}
MpApplicationJob::UpdatePerson(person_id) => {
misc_service
app_services
.miscellaneous_service
.update_person_and_notify_users(&person_id)
.await
}
MpApplicationJob::UpdateMetadataGroup(metadata_group_id) => {
misc_service.update_metadata_group(&metadata_group_id).await
app_services
.miscellaneous_service
.update_metadata_group(&metadata_group_id)
.await
}
MpApplicationJob::UpdateGithubExercises => {
app_services.fitness_service.update_github_exercises().await
}
MpApplicationJob::UpdateGithubExercises => fitness_service.update_github_exercises().await,
MpApplicationJob::RecalculateCalendarEvents => {
misc_service.recalculate_calendar_events().await
app_services
.miscellaneous_service
.recalculate_calendar_events()
.await
}
MpApplicationJob::PerformBackgroundTasks => {
app_services
.miscellaneous_service
.perform_background_jobs()
.await
}
MpApplicationJob::PerformExport(user_id) => {
app_services.exporter_service.perform_export(user_id).await
}
MpApplicationJob::PerformBackgroundTasks => misc_service.perform_background_jobs().await,
MpApplicationJob::PerformExport(user_id) => exporter_service.perform_export(user_id).await,
MpApplicationJob::UpdateExerciseLibrary => {
fitness_service.deploy_update_exercise_library_job().await
app_services
.fitness_service
.deploy_update_exercise_library_job()
.await
}
MpApplicationJob::SyncIntegrationsData => {
integration_service
.yank_integrations_data()
.await
.trace_ok();
integration_service
.sync_integrations_data_to_owned_collection()
app_services
.integration_service
.sync_integrations_data()
.await
}
};
Expand All @@ -120,21 +146,33 @@ pub async fn perform_mp_application_job(

pub async fn perform_lp_application_job(
information: LpApplicationJob,
misc_service: Data<Arc<MiscellaneousService>>,
integration_service: Data<Arc<IntegrationService>>,
app_services: Data<Arc<AppServices>>,
) -> Result<(), Error> {
ryot_log!(trace, "Started job {:?}", information);
let status = match information {
LpApplicationJob::HandleAfterMediaSeenTasks(seen) => {
misc_service.handle_after_media_seen_tasks(seen).await
app_services
.miscellaneous_service
.handle_after_media_seen_tasks(seen)
.await
}
LpApplicationJob::HandleEntityAddedToCollectionEvent(collection_to_entity_id) => {
integration_service
app_services
.integration_service
.handle_entity_added_to_collection_event(collection_to_entity_id)
.await
}
LpApplicationJob::HandleOnSeenComplete(id) => {
integration_service.handle_on_seen_complete(id).await
app_services
.integration_service
.handle_on_seen_complete(id)
.await
}
LpApplicationJob::DeleteAllApplicationCache => {
app_services
.miscellaneous_service
.delete_all_application_cache()
.await
}
};
status.map_err(|e| Error::Failed(Arc::new(e.message.into())))
Expand Down
Loading

0 comments on commit 5e1a32f

Please sign in to comment.