(&self, install_config: InstallConfig)
| 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 | |
| 60 | CREATE TYPE fang_task_state AS ENUM ('new', 'in_progress', 'failed', 'finished', 'retried'); |
| 61 | |
| 62 | CREATE 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 | |
| 75 | CREATE INDEX fang_tasks_state_index ON fang_tasks(state); |
| 76 | CREATE INDEX fang_tasks_type_index ON fang_tasks(task_type); |
| 77 | CREATE INDEX fang_tasks_scheduled_at_index ON fang_tasks(scheduled_at); |
| 78 | CREATE INDEX fang_tasks_uniq_hash ON fang_tasks(uniq_hash); |
| 79 | "#}, |
| 80 | r"DROP TABLE fang_tasks;", |
nothing calls this directly
no test coverage detected