Sha256: 8e6896a6990b29ba88818c53437a5a04d02cc80109fc982869818f76e1141f17

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

require_relative '../lib/daemon_runner'

class MyService
  class Tasks
    class Foo
      def run!
        puts 'foo'
        'foo'
      end
    end
  end
end

class MyService
  class Tasks
    class Bar
      def schedule
        [:cron, '*/1 * * * *']
      end

      def run!(name)
        puts name
        name
      end
    end
  end
end

class MyService
  class Tasks
    class Baz
      class << self
        def schedule
          [:interval, 10]
        end

        def run!(args)
          sleep 10
          name = args[0]
          reason = args[1]
          puts name
          puts reason
          name
        end

        def task_id
          'long-running-task'
        end
      end
    end
  end
end

class MyService
  class Tasks
    class Quiz
      def initialize
        @task_id = 'long-running-task'
        @schedule = [:interval, '30s']
      end

      def foo!(args)
        sleep 10
        puts 'Firing error'
        sargs
      end
    end
  end
end

class MyService
  class Client < DaemonRunner::Client
    def tasks
      [
        [::MyService::Tasks::Foo.new, 'run!'],
        [::MyService::Tasks::Bar.new, 'run!', 'bar'],
        [::MyService::Tasks::Baz, 'run!', 'baz', 'because'],
        [::MyService::Tasks::Quiz.new, 'foo!', 'blarg', 'assdg']
      ]
    end
  end
end

options = {}
service = MyService::Client.new(options)
service.start!

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daemon_runner-0.4.3 examples/example1.rb
daemon_runner-0.4.2 examples/example1.rb
daemon_runner-0.4.1 examples/example1.rb
daemon_runner-0.4.0 examples/example1.rb