MCPcopy Create free account
hub / github.com/Wulf/create-rust-app / install

Method install

crates/create-rust-app_cli/src/plugins/tasks.rs:23–159  ·  view source on GitHub ↗
(&self, install_config: InstallConfig)

Source from the content-addressed store, hash-verified

21 }
22
23 fn install(&self, install_config: InstallConfig) -> Result<()> {
24 // ===============================
25 // Check if the plugin is supported
26 // ===============================
27
28 if install_config.backend_database != BackendDatabase::Postgres {
29 return Err(anyhow::anyhow!("The tasks plugin only supports Postgres"));
30 }
31
32 if install_config.backend_framework != BackendFramework::ActixWeb {
33 return Err(anyhow::anyhow!("The tasks plugin only supports actix-web"));
34 }
35
36 // ===============================
37 // Copy over template files
38 // ===============================
39
40 for filename in Asset::iter() {
41 let file_contents = Asset::get(filename.as_ref()).unwrap();
42 let mut file_path = std::path::PathBuf::from(&install_config.project_dir);
43 file_path.push(filename.as_ref());
44 let mut directory_path = std::path::PathBuf::from(&file_path);
45 directory_path.pop();
46
47 add_file_msg(filename.as_ref());
48 std::fs::create_dir_all(directory_path)?;
49 std::fs::write(file_path, file_contents.data)?;
50 }
51
52 // ===============================
53 // Create migration
54 // ===============================
55
56 crate::content::migration::create(
57 "plugin_tasks",
58 indoc! {r#"CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
59
60CREATE TYPE fang_task_state AS ENUM ('new', 'in_progress', 'failed', 'finished', 'retried');
61
62CREATE TABLE fang_tasks (
63 id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
64 metadata jsonb NOT NULL,
65 error_message TEXT,
66 state fang_task_state DEFAULT 'new' NOT NULL,
67 task_type VARCHAR DEFAULT 'common' NOT NULL,
68 uniq_hash CHAR(64),
69 retries INTEGER DEFAULT 0 NOT NULL,
70 scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
71 created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
72 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
73);
74
75CREATE INDEX fang_tasks_state_index ON fang_tasks(state);
76CREATE INDEX fang_tasks_type_index ON fang_tasks(task_type);
77CREATE INDEX fang_tasks_scheduled_at_index ON fang_tasks(scheduled_at);
78CREATE INDEX fang_tasks_uniq_hash ON fang_tasks(uniq_hash);
79"#},
80 r"DROP TABLE fang_tasks;",

Callers

nothing calls this directly

Calls 4

add_file_msgFunction · 0.85
replaceFunction · 0.85
add_dependencyFunction · 0.85
createFunction · 0.50

Tested by

no test coverage detected