Class: Newshound::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_to_que_scheduleObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/newshound/install/install_generator.rb', line 17

def add_to_que_schedule
  que_schedule_path = "config/que_schedule.yml"

  if File.exist?(que_schedule_path)
    say_status :info, "Adding Newshound job to #{que_schedule_path}", :blue

    # Read existing YAML
    existing_config = YAML.load_file(que_schedule_path) || {}

    # Add Newshound job if not already present
    unless existing_config.key?("Newshound::DailyReportJob")
      # Append the configuration to the file
      append_to_file que_schedule_path do
        <<~YAML

          # Newshound daily report job - sends exception and queue reports to Slack
          Newshound::DailyReportJob:
            cron: "0 9 * * *"  # Daily at 9:00 AM - adjust as needed
            queue: default
            args: []
        YAML
      end

      say_status :success, "Added Newshound::DailyReportJob to que_schedule.yml", :green
    else
      say_status :skip, "Newshound::DailyReportJob already exists in que_schedule.yml", :yellow
    end
  else
    say_status :warning, "#{que_schedule_path} not found. Creating it with Newshound job.", :yellow
    create_file que_schedule_path do
      <<~YAML
        # Que-scheduler configuration
        # See https://github.com/hlascelles/que-scheduler for more information

        # Newshound daily report job - sends exception and queue reports to Slack
        Newshound::DailyReportJob:
          cron: "0 9 * * *"  # Daily at 9:00 AM - adjust as needed
          queue: default
          args: []
      YAML
    end
  end
end

#create_initializerObject



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

def create_initializer
  template "newshound.rb", "config/initializers/newshound.rb"
end

#display_post_install_messageObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/newshound/install/install_generator.rb', line 61

def display_post_install_message
  say ""
  say "===============================================================================", :green
  say "  Newshound has been successfully installed!", :green
  say ""
  say "  Next steps:", :yellow
  say "  1. Configure your Slack webhook URL in config/initializers/newshound.rb"
  say "  2. Adjust the report schedule in config/que_schedule.yml if needed"
  say "  3. Restart your Rails server and Que workers"
  say ""
  say "  To test your configuration, run:", :cyan
  say "    rails runner 'Newshound.report!'"
  say ""
  say "  For more information, visit:", :blue
  say "    https://github.com/salbanez/newshound"
  say "===============================================================================", :green
  say ""
end