-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into langs-api
- Loading branch information
Showing
64 changed files
with
2,061 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
2 changes: 2 additions & 0 deletions
2
services/headless-lms/migrations/20230707103238_add_user_reasearch_consent_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add down migration script here | ||
DROP TABLE user_research_consents; |
18 changes: 18 additions & 0 deletions
18
services/headless-lms/migrations/20230707103238_add_user_reasearch_consent_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'; |
Oops, something went wrong.