Class: Emque::Consuming::Tasks

Inherits:
Object
  • Object
show all
Includes:
Helpers, Rake::DSL
Defined in:
lib/emque/consuming/tasks.rb

Instance Method Summary collapse

Instance Method Details

#install_tasksObject



7
8
9
10
11
12
13
14
15
16
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/emque/consuming/tasks.rb', line 7

def install_tasks
  namespace :emque do
    desc "Show the current configuration of a running instance " +
         "(accepts SOCKET)"
    task :configuration do
      puts with_transmitter(:send, :configuration)
    end

    desc "Start a pry console"
    task :console do
      Emque::Consuming::Runner.new.console
    end

    namespace :errors do
      desc "Clear all outstanding errors (accepts SOCKET)"
      task :clear do
        puts with_transmitter(:send, :errors, :clear)
      end

      desc "Change the number of seconds to SECONDS before future " +
           "errors expire (accepts SOCKET)"
      task :expire_after do
        seconds = ENV.fetch("SECONDS", 3600)
        puts with_transmitter(:send, :errors, :expire_after, seconds)
      end

      namespace :limit do
        desc "Decrease the error limit (accepts SOCKET)"
        task :down do
          puts with_transmitter(:send, :errors, :down)
        end

        desc "Increase the error limit (accepts SOCKET)"
        task :up do
          puts with_transmitter(:send, :errors, :up)
        end
      end
    end

    desc "Show the available routes"
    task :routes do
      require "table_print"
      tp(
        [].tap { |routes|
          mappings = router.instance_eval { @mappings }

          mappings.each { |topic, maps|
            maps.each { |mapping|
              mapping.instance_eval { @mapping }.each { |route, method|
                routes << {
                  :route => route,
                  :topic => topic,
                  :consumer => mapping.consumer,
                  :method => method,
                  :workers => router.workers(topic)
                }
              }
            }
          }
        },
        {:route => {:width => 50}},
        :topic,
        :consumer,
        :method,
        :workers
      )
    end

    desc "Restart the workers inside a running instance " +
         "(does not reload code; accepts SOCKET)"
    task :restart do
      with_transmitter(:send, :restart)
    end

    desc "Show the current status of a running instance " +
         "(accepts SOCKET)"
    task :status do
      puts with_transmitter(:send, :status)
    end

    desc "Start a new instance (accepts PIDFILE, DAEMON)"
    task :start do
      daemon = ENV.fetch("DAEMON", false)
      pidfile = ENV.fetch("PIDFILE", "tmp/pids/#{config.app_name}.pid")

      Emque::Consuming::Runner.new({
        :daemon => daemon,
        :pidfile => pidfile
      }).start
    end

    desc "Stop a running instance (accepts SOCKET)"
    task :stop do
      resp = with_transmitter(:send, :stop)
      puts resp.length > 0 ? resp : "stopped"
    end
  end
end