Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into langs-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Heliozoa committed Aug 8, 2023
2 parents 29b44e8 + 4004456 commit bc588b6
Show file tree
Hide file tree
Showing 64 changed files with 2,061 additions and 828 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ const UserNavigationControls: React.FC<React.PropsWithChildren<UserNavigationCon
{t("settings")}
</Button>
</li>

<li>
<a href={"/user-settings"}>
<Button
className={css`
color: ${baseTheme.colors.green[600]}!important;
`}
size="medium"
variant="primary"
>
{t("user-settings")}
</Button>
</a>
</li>

<li className={cx(styles)}>
<Button
className={css`
Expand Down
2 changes: 2 additions & 0 deletions services/headless-lms/Cargo.lock

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

4 changes: 4 additions & 0 deletions services/headless-lms/entrypoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ headless-lms-server = { path = "../server" }
actix-web = "4.3.1"
# Flexible concrete Error type built on std::error::Error
anyhow = "1.0.71"
# Combinators and utilities for working with Futures, Streams, Sinks, and the AsyncRead and AsyncWrite traits.
futures-util = "0.3.28"
# A runtime for writing reliable network applications without compromising speed.
tokio = "1.29.1"
61 changes: 46 additions & 15 deletions services/headless-lms/entrypoint/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
use std::future::Future;

use futures_util::FutureExt;
use headless_lms_server::programs;

/// The entrypoint to all the binaries provided by the project.
/// Expects program name as the first argument.
#[actix_web::main]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
let program_name = std::env::args()
.nth(1)
.expect("No program name provided as the first argument.");
match program_name.as_str() {
"doc-file-generator" => programs::doc_file_generator::main().await?,
"email-deliver" => programs::email_deliver::main().await?,
"ended-exams-processor" => programs::ended_exams_processor::main().await?,
let future = match program_name.as_str() {
"doc-file-generator" => programs::doc_file_generator::main().boxed_local(),
"email-deliver" => programs::email_deliver::main().boxed_local(),
"ended-exams-processor" => programs::ended_exams_processor::main().boxed_local(),
"open-university-registration-link-fetcher" => {
programs::open_university_registration_link_fetcher::main().await?
programs::open_university_registration_link_fetcher::main().boxed_local()
}
"regrader" => programs::regrader::main().boxed_local(),
"seed" => programs::seed::main().boxed_local(),
"service-info-fetcher" => programs::service_info_fetcher::main().boxed_local(),
"peer-review-updater" => programs::peer_review_updater::main().boxed_local(),
"start-server" => {
// we'll run the server on the actix runtime without boxing it
actix_run(programs::start_server::main())?;
return Ok(());
}
"sorter" => {
// not async so no need to involve a runtime
programs::sorter::sort()?;
return Ok(());
}
"regrader" => programs::regrader::main().await?,
"seed" => programs::seed::main().await?,
"service-info-fetcher" => programs::service_info_fetcher::main().await?,
"peer-review-updater" => programs::peer_review_updater::main().await?,
"start-server" => programs::start_server::main().await?,
"sorter" => programs::sorter::sort()?,
"sync-tmc-users" => programs::sync_tmc_users::main().await?,
"calculate-page-visit-stats" => programs::calculate_page_visit_stats::main().await?,
"sync-tmc-users" => programs::sync_tmc_users::main().boxed_local(),
"calculate-page-visit-stats" => programs::calculate_page_visit_stats::main().boxed_local(),
_ => panic!("Unknown program name: {}", program_name),
};
tokio_run(future)?;

Ok(())
}

fn actix_run<F>(f: F) -> anyhow::Result<()>
where
F: Future<Output = anyhow::Result<()>>,
{
let rt = actix_web::rt::Runtime::new()?;
rt.block_on(f)?;
Ok(())
}

// tokio's default runtime can use multiple threads, so it's less prone to stack overflows when spawning lots of tasks
// making it better suited for non-actix-web tasks
fn tokio_run<F>(f: F) -> anyhow::Result<()>
where
F: Future<Output = anyhow::Result<()>>,
{
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(f)?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add down migration script here
DROP TABLE user_research_consents;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Add up migration script here
CREATE TABLE user_research_consents (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users,
research_consent BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
deleted_at TIMESTAMP WITH TIME ZONE,
CONSTRAINT user_id_when_not_deleted UNIQUE NULLS NOT DISTINCT(user_id, deleted_at)
);
CREATE TRIGGER set_timestamp BEFORE
UPDATE ON user_research_consents FOR EACH ROW EXECUTE PROCEDURE trigger_set_timestamp();
COMMENT ON TABLE user_research_consents IS 'Stores information whether a student has consented to participate on research done on courses';
COMMENT ON COLUMN user_research_consents.user_id IS 'The user for which the consent belongs to';
COMMENT ON COLUMN user_research_consents.research_consent IS 'Whether or not the student has given a consent to research';
COMMENT ON COLUMN user_research_consents.created_at IS 'Timestamp when the record was created.';
COMMENT ON COLUMN user_research_consents.updated_at IS 'Timestamp when the record was last updated. The field is updated automatically by the set_timestamp trigger.';
COMMENT ON COLUMN user_research_consents.deleted_at IS 'Timestamp when the record was deleted. If null, the record is not deleted.';
Loading

0 comments on commit bc588b6

Please sign in to comment.