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

Anilist importer #1138

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ resolver = "2"
[workspace.dependencies]
askama = "0.12.1"
anyhow = "=1.0.93"
apalis = { version = "=0.6.2", features = ["limit"] }
apalis = { version = "=0.6.2", features = ["catch-panic", "limit"] }
apalis-cron = "=0.6.2"
argon2 = "=0.6.0-pre.1"
async-graphql = { version = "=7.0.11", features = [
Expand Down
1 change: 0 additions & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ statistics-resolver = { path = "../../crates/resolvers/statistics" }
statistics-service = { path = "../../crates/services/statistics" }
supporting-service = { path = "../../crates/services/supporting" }
tokio = { workspace = true }
tower = { workspace = true }
tower-http = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions apps/backend/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ 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>,
pub fitness_service: Arc<FitnessService>,
pub supporting_service: Arc<SupportingService>,
pub statistics_service: Arc<StatisticsService>,
pub integration_service: Arc<IntegrationService>,
pub miscellaneous_service: Arc<MiscellaneousService>,
Expand Down Expand Up @@ -145,9 +146,10 @@ pub async fn create_app_services(
.layer(cors);
AppServices {
app_router,
fitness_service,
importer_service,
exporter_service,
fitness_service,
supporting_service,
statistics_service,
integration_service,
miscellaneous_service,
Expand Down
32 changes: 17 additions & 15 deletions apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ use std::{
use anyhow::{bail, Result};
use apalis::{
layers::{limit::RateLimitLayer as ApalisRateLimitLayer, WorkerBuilderExt},
prelude::{MemoryStorage, MessageQueue, Monitor, WorkerBuilder, WorkerFactoryFn},
prelude::{MemoryStorage, Monitor, WorkerBuilder, WorkerFactoryFn},
};
use apalis_cron::{CronStream, Schedule};
use aws_sdk_s3::config::Region;
use background::ApplicationJob;
use common_utils::{ryot_log, PROJECT_NAME, TEMP_DIR};
use dependent_models::CompleteExport;
use env_utils::APP_VERSION;
use futures::future::join_all;
use logs_wheel::LogFileInitializer;
use migrations::Migrator;
use schematic::schema::{SchemaGenerator, TypeScriptRenderer, YamlTemplateRenderer};
use sea_orm::{ConnectionTrait, Database, DatabaseConnection};
use sea_orm_migration::MigratorTrait;
use tokio::{
Expand Down Expand Up @@ -115,16 +117,6 @@ async fn main() -> Result<()> {
.unwrap_or_else(|_| chrono_tz::Etc::GMT);
ryot_log!(info, "Timezone: {}", tz);

join_all([
perform_application_job_storage
.clone()
.enqueue(ApplicationJob::SyncIntegrationsData),
perform_application_job_storage
.clone()
.enqueue(ApplicationJob::UpdateExerciseLibrary),
])
.await;

let app_services = create_app_services(
db,
tz,
Expand All @@ -135,10 +127,16 @@ async fn main() -> Result<()> {
)
.await;

if cfg!(debug_assertions) {
use dependent_models::CompleteExport;
use schematic::schema::{SchemaGenerator, TypeScriptRenderer, YamlTemplateRenderer};
join_all(
[
ApplicationJob::SyncIntegrationsData,
ApplicationJob::UpdateExerciseLibrary,
]
.map(|job| app_services.supporting_service.perform_application_job(job)),
)
.await;

if cfg!(debug_assertions) {
// TODO: Once https://github.com/rust-lang/cargo/issues/3946 is resolved
let base_dir = PathBuf::from(BASE_DIR)
.parent()
Expand Down Expand Up @@ -191,6 +189,7 @@ async fn main() -> Result<()> {
.register(
WorkerBuilder::new("daily_background_jobs")
.enable_tracing()
.catch_panic()
.data(miscellaneous_service_1.clone())
.backend(
// every day
Expand All @@ -201,6 +200,7 @@ async fn main() -> Result<()> {
.register(
WorkerBuilder::new("frequent_jobs")
.enable_tracing()
.catch_panic()
.data(integration_service_1.clone())
.data(fitness_service_2.clone())
.backend(CronStream::new_with_timezone(
Expand All @@ -213,6 +213,7 @@ async fn main() -> Result<()> {
.register(
WorkerBuilder::new("perform_core_application_job")
.enable_tracing()
.catch_panic()
.data(integration_service_2.clone())
.data(miscellaneous_service_3.clone())
.backend(perform_core_application_job_storage)
Expand All @@ -221,6 +222,7 @@ async fn main() -> Result<()> {
.register(
WorkerBuilder::new("perform_application_job")
.enable_tracing()
.catch_panic()
.data(fitness_service_1.clone())
.data(exporter_service_1.clone())
.data(importer_service_1.clone())
Expand Down Expand Up @@ -251,9 +253,9 @@ fn init_tracing() -> Result<()> {
let tmp_dir = PathBuf::new().join(TEMP_DIR);
create_dir_all(&tmp_dir)?;
let log_file = LogFileInitializer {
max_n_old_files: 2,
directory: tmp_dir,
filename: PROJECT_NAME,
max_n_old_files: 2,
preferred_max_file_size_mib: 1,
}
.init()?;
Expand Down
32 changes: 6 additions & 26 deletions apps/frontend/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,10 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const defaultColorScheme = colorScheme || "light";
if (toastHeaders) extendResponseHeaders(headers, toastHeaders);

const userAgent = request.headers.get("user-agent") || "";
const isIOS = /iPad|iPhone|iPod/.test(userAgent);
let isIOS18 = false;

if (isIOS) {
const match = userAgent.match(/OS (\d+)_(\d+)_?(\d+)?/);
if (match) {
const version = Number.parseInt(match[1], 10);
isIOS18 = version >= 18;
}
}

return data({ toast, defaultColorScheme, isIOS18 }, { headers });
return data({ toast, defaultColorScheme }, { headers });
};

const DefaultHeadTags = () => {
const loaderData = useLoaderData<typeof loader>();

return (
<>
<meta charSet="utf-8" />
Expand All @@ -128,12 +114,7 @@ const DefaultHeadTags = () => {
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no, user-scalable=no, viewport-fit=cover"
/>
<link rel="manifest" href="/manifest.json" />
<link
rel="apple-touch-icon"
href={
loaderData.isIOS18 ? "/icon-192x192.png" : "/apple-touch-icon.png"
}
/>
<link rel="apple-touch-icon" href={"/icon-192x192.png"} />
</>
);
};
Expand All @@ -153,18 +134,17 @@ export default function App() {
<body>
<QueryClientProvider client={queryClient}>
<MantineProvider
classNamesPrefix="mnt"
theme={theme}
classNamesPrefix="mnt"
forceColorScheme={loaderData.defaultColorScheme}
>
<ConfirmationMountPoint />
{navigation.state === "loading" ||
navigation.state === "submitting" ? (
{["loading", "submitting"].includes(navigation.state) ? (
<Loader
pos="fixed"
right={10}
top={10}
size="sm"
right={10}
pos="fixed"
color="yellow"
style={{ zIndex: 10 }}
/>
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/app/routes/_dashboard.analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
};

export const meta = (_args: MetaArgs<typeof loader>) => {
return [{ title: "Fitness Analytics | Ryot" }];
return [{ title: "Analytics | Ryot" }];
};

const useTimeSpanSettings = () => {
Expand Down Expand Up @@ -256,10 +256,10 @@ export default function Page() {
<ExercisesChart />
</Grid.Col>
<Grid.Col span={{ base: 12, md: 6 }}>
<TimeOfDayChart />
<StatisticsCard />
</Grid.Col>
<Grid.Col span={{ base: 12, md: 6 }}>
<StatisticsCard />
<TimeOfDayChart />
</Grid.Col>
<Grid.Col span={12}>
<ActivitySection />
Expand Down
1 change: 0 additions & 1 deletion crates/background/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
apalis = { workspace = true }
chrono = { workspace = true }
chrono-tz = { workspace = true }
database-models = { path = "../models/database" }
Expand Down
Loading
Loading