Class: RustOnBackground::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_cargo_tomlObject



18
19
20
21
22
# File 'lib/generators/install/install_generator.rb', line 18

def copy_cargo_toml
  @db_adapter = detect_database_adapter
  @db_feature = database_feature_for(@db_adapter)
  template "Cargo.toml.erb", "app/jobs/rust/Cargo.toml"
end

#copy_rust_source_filesObject



24
25
26
27
28
29
# File 'lib/generators/install/install_generator.rb', line 24

def copy_rust_source_files
  copy_file "main.rs", "app/jobs/rust/src/main.rs"
  copy_file "worker.rs", "app/jobs/rust/src/worker.rs"
  copy_file "scheduler.rs", "app/jobs/rust/src/scheduler.rs"
  copy_file "jobs/mod.rs", "app/jobs/rust/src/jobs/mod.rs"
end

#create_config_fileObject



31
32
33
34
# File 'lib/generators/install/install_generator.rb', line 31

def create_config_file
  @database_url = build_database_url
  template "config.toml.erb", "app/jobs/rust/config.#{Rails.env}.toml"
end

#create_rake_tasksObject



36
37
38
# File 'lib/generators/install/install_generator.rb', line 36

def create_rake_tasks
  copy_file "rust_on_background.rake", "lib/tasks/rust_on_background.rake"
end

#create_rust_jobs_dirObject



12
13
14
15
16
# File 'lib/generators/install/install_generator.rb', line 12

def create_rust_jobs_dir
  empty_directory "app/jobs/rust"
  empty_directory "app/jobs/rust/src"
  empty_directory "app/jobs/rust/src/jobs"
end

#show_post_install_messageObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/generators/install/install_generator.rb', line 57

def show_post_install_message
  say ""
  say "Rust jobs created successfully!", :green
  say ""
  say "Configuration:"
  say "  Database: Using config/database.yml (#{detect_database_adapter})"
  say "  Config: app/jobs/rust/config.#{Rails.env}.toml"
  say ""
  say "Next steps:"
  say "  1. Review app/jobs/rust/config.#{Rails.env}.toml"
  say "  2. Generate a file for some job, example: rails generate rust_on_background:job import_big_xlsx filepath:string"
  say "  3. Write the logic in the job file you created somewhere at: app/jobs/rust/src/jobs/import_big_xlsx.rs"
  say "  4. Call it from somewhere in your app RustOnBackground.perform('import_big_xlsx', filepath: '/path/to/file.xlsx')"
  say "  5. Compile: rake rust_on_background:build"
  say "  6. Start the background jobs: rake rust_on_background:start"
  say ""
  say "All rake tasks available:"
  say "  rake rust_on_background:build"
  say "  rake rust_on_background:start                # start all queues"
  say "  rake rust_on_background:start[queue_name]    # start specific queue"
  say "  rake rust_on_background:stop                 # stop all queues"
  say "  rake rust_on_background:stop[queue_name]     # stop specific queue"
  say "  rake rust_on_background:restart"
  say "  rake rust_on_background:rebuild              # stop, build, start"
  say "  rake rust_on_background:status"
  say "  rake rust_on_background:scheduler:start      # start scheduler (one per Redis)"
  say "  rake rust_on_background:scheduler:stop       # stop scheduler"
  say ""
  say "Environment-specific configs:"
  say "  config.development.toml, config.production.toml, config.test.toml"
  say ""
end

#update_gitignoreObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/install/install_generator.rb', line 40

def update_gitignore
  gitignore_path = Rails.root.join(".gitignore")
  return unless File.exist?(gitignore_path)

  content = File.read(gitignore_path)
  return if content.include?("rust_on_background")

  append_to_file ".gitignore", <<~GITIGNORE

    # rust_on_background
    /app/jobs/rust/target
    /app/jobs/rust/Cargo.lock
  GITIGNORE

  say "Updated .gitignore with rust_on_background /app/jobs/rust/target and /app/jobs/rust/Cargo.lock", :green
end