SlideShare uma empresa Scribd logo
1 de 30
Rooster
Rooster
•    It does the same thing everyday at the
    same time, whether you are sleeping or not
Rooster

• Designed to run periodic tasks, on schedule
History
• Previously we used the daemons gem plus
  the daemon generator plugin.
• Headaches:
 • Each daemon is a separate process.
 • Not very DRY:
Not DRY
• Each daemon has two files:
 • The actual code that runs as a daemon
    (e.g. network_point_update_daemon.rb)
•
Not DRY
• Each daemon has two files:
 • And a daemon control script
    (e.g. network_point_update_daemon_ctl)
•
Not DRY
• The only bit of code that actually does our work:
  AppUser.daily_amount_grant

• The Rails environment is loaded within each
  daemon process! Not good for memory.
• No centralized logging/error handling; poignantly
  recognized when we wanted exceptions emailed to
  us.
• Management of each daemon process required
  another entry into monit's config file (eww!):
Back To The Future
(of scheduled tasks)
Rooster
Rooster
What does it do?
Rooster
     What does it do?
Scratches the itches of our previous
configuration
Rooster
                            It’s DRY
• One daemon, monitored by monit
• One Rails environment, loaded once
• Easier management:  TCP server (easily
  accessed by telnet), rake tasks, more to come...
• Centralized and configurable error handling and
  logging:
  Rooster::Runner.error_handler = lambda { |e| HoptoadNotifier.notify(e) }
How?



•   Rooster leverages 3 (optionally 4) excellent open source bits of
    software:
How?


•   Rooster leverages 3 (optionally 4) excellent open source bits of
    software:

    •   EventMachine:  provides event-driven I/O using the Reactor
        pattern.  It lets you write network clients and servers without
        handling sockets.
How?

•   Rooster leverages 3 (optionally 4) excellent open source bits of
    software:

    •   EventMachine:  provides event-driven I/O using the Reactor
        pattern.  It lets you write network clients and servers without
        handling sockets.

    •   Rufus Scheduler:   a Ruby gem for scheduling pieces of
        code (can leverage EventMachine if available).
How?
•   Rooster leverages 3 (optionally 4) excellent open source bits of
    software:

    •   EventMachine:  provides event-driven I/O using the Reactor
        pattern.  It lets you write network clients and servers without
        handling sockets.

    •   Rufus Scheduler:   a Ruby gem for scheduling pieces of
        code (can leverage EventMachine if available).

    •   daemons:  A Ruby gem that provides an easy way to wrap
        existing ruby code to be run as a daemon, and to be
        controlled by simple start/stop/restart commands.   (I know we
        moved away from our previous daemons-based solution, but
        not all daemons are bad).
How?
•   Rooster leverages 3 (optionally 4) excellent open source bits of
    software:

    •   EventMachine:  provides event-driven I/O using the Reactor
        pattern.  It lets you write network clients and servers without
        handling sockets.

    •   Rufus Scheduler:   a Ruby gem for scheduling pieces of
        code (can leverage EventMachine if available).

    •   daemons:  A Ruby gem that provides an easy way to wrap
        existing ruby code to be run as a daemon and to be controlled
        by simple start/stop/restart commands.   (I know we moved
        away from our previous daemons-based solution, but not all
        daemons are bad).

    •   Chronic (Optional) - A handy gem for natural language date/
        time parsing.
How?



•   These components fit together thusly:
How?


•   These components fit together thusly:

    •   The rooster daemon is started, and then kicks off the
        Rooster::Runner.
How?

•   These components fit together thusly:

    •   The rooster daemon is started, and then kicks off the
        Rooster::Runner.

    •   Rooster::Runner runs the main EventMachine reactor loop,
        loads a Rufus::Scheduler, loads (and optionally schedules)
        each rooster task, and starts the ControlServer.
How?

•   These components fit together thusly:

    •   The rooster daemon is started, and then kicks off the
        Rooster::Runner.

    •   Rooster::Runner runs the main EventMachine reactor loop,
        loads a Rufus::Scheduler, loads (and optionally schedules)
        each rooster task, and starts the ControlServer.

    •   Rooster::ControlServer is a TCP-based server that listens for
        Rooster control commands (e.g.  schedule, unschedule, exit,
        etc.).
How?
•   These components fit together thusly:

    •   The rooster daemon is started, and then kicks off the
        Rooster::Runner.

    •   Rooster::Runner runs the main EventMachine reactor loop,
        loads a Rufus::Scheduler, loads (and optionally schedules)
        each rooster task, and starts the ControlServer.

    •   Rooster::ControlServer is a TCP-based server that listens for
        Rooster control commands (e.g.  schedule, unschedule, exit,
        etc.).

    •   Rooster::ControlClient issues commands to the
        ControlServer; used mainly as a rake helper.
I kan haz A EXAMPLE Pleez?
Example
•   I want a task that kills all kittens at 4:20pm every day

•   > script/generate rooster_task KittenKiller

•   Generates a new templated task in:
    RAILS_ROOT/lib/rooster/tasks/kitten_killer_task.rb




•   rake rooster:launch
    (and then maybe `rake rooster:start TASK=KittenKillerTask`)
Commands


•   Tag-based commands are handy for controlling only a subset of
    available tasks

    •   For example, we have separate rooster tasks running on app1
        and app3, and are controlled with those server-specific tags.
Future Goals
•   Make rooster task scheduling blocks DRYer, especially by
    abstracting away the ActiveRecord connection pool cleanup.

•   Refactor Rooster::Runner (prettier code).

•   Add scripts (e.g. script/rooster daemon:start)

•   On daemon launch, autostart tasks having a certain tag (or
    accept a lambda, e.g.
    launch_if => lamba { |task| task.tags.include?(“app1”) } )
References
•   http://daemons.rubyforge.org/

•   http://github.com/jmettraux/rufus-scheduler/tree/master

•   http://rubyeventmachine.com/

•   http://github.com/findchris/rooster/tree/master
The Rooster Has Spoken
But wait, there’s more!
Single Slide: Create a Rails
 plugin and push to github
•   First, go to github.com, signup, add ssh keys, and create a new
    project

•   Then...

Mais conteúdo relacionado

Mais procurados

Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
Doug Chang
 
Crash reports pycodeconf
Crash reports pycodeconfCrash reports pycodeconf
Crash reports pycodeconf
lauraxthomson
 
2010 vampir workshop_iu_configuration
2010 vampir workshop_iu_configuration2010 vampir workshop_iu_configuration
2010 vampir workshop_iu_configuration
PTIHPA
 
2010-02-09 Reactor Pattern & Event Driven Programming
2010-02-09 Reactor Pattern & Event Driven Programming2010-02-09 Reactor Pattern & Event Driven Programming
2010-02-09 Reactor Pattern & Event Driven Programming
Lin Jen-Shin
 

Mais procurados (20)

Infrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using PrometheusInfrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using Prometheus
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
 
Kafka Summit NYC 2017 - Running Hundreds of Kafka Clusters with 5 People
Kafka Summit NYC 2017 - Running Hundreds of Kafka Clusters with 5 PeopleKafka Summit NYC 2017 - Running Hundreds of Kafka Clusters with 5 People
Kafka Summit NYC 2017 - Running Hundreds of Kafka Clusters with 5 People
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
 
Crash reports pycodeconf
Crash reports pycodeconfCrash reports pycodeconf
Crash reports pycodeconf
 
AMC Minor Technical Issues
AMC Minor Technical IssuesAMC Minor Technical Issues
AMC Minor Technical Issues
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
 
2010 vampir workshop_iu_configuration
2010 vampir workshop_iu_configuration2010 vampir workshop_iu_configuration
2010 vampir workshop_iu_configuration
 
Streaming and Messaging
Streaming and MessagingStreaming and Messaging
Streaming and Messaging
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
Apache samza
Apache samzaApache samza
Apache samza
 
Introduction to Systems Management with SaltStack
Introduction to Systems Management with SaltStackIntroduction to Systems Management with SaltStack
Introduction to Systems Management with SaltStack
 
Ractor's speed is not light-speed
Ractor's speed is not light-speedRactor's speed is not light-speed
Ractor's speed is not light-speed
 
Let the alpakka pull your stream
Let the alpakka pull your streamLet the alpakka pull your stream
Let the alpakka pull your stream
 
How to Make MPI Awesome: A Proposal for MPI Sessions
How to Make MPI Awesome: A Proposal for MPI SessionsHow to Make MPI Awesome: A Proposal for MPI Sessions
How to Make MPI Awesome: A Proposal for MPI Sessions
 
2010-02-09 Reactor Pattern & Event Driven Programming
2010-02-09 Reactor Pattern & Event Driven Programming2010-02-09 Reactor Pattern & Event Driven Programming
2010-02-09 Reactor Pattern & Event Driven Programming
 
Perl in Teh Cloud
Perl in Teh CloudPerl in Teh Cloud
Perl in Teh Cloud
 
HTTP/2 Server Push
HTTP/2 Server PushHTTP/2 Server Push
HTTP/2 Server Push
 
Async await...oh wait!
Async await...oh wait!Async await...oh wait!
Async await...oh wait!
 

Destaque

Commmpete por Diana Vinay
Commmpete por Diana VinayCommmpete por Diana Vinay
Commmpete por Diana Vinay
guest6ef6a7
 
InvestigacióN
InvestigacióNInvestigacióN
InvestigacióN
yanniny
 
Current and future challenges of the poultry industry
Current and future challenges of the poultry industryCurrent and future challenges of the poultry industry
Current and future challenges of the poultry industry
mithu mehr
 
La Tierra Chaleco 7 A 17 Y 24
La Tierra Chaleco 7 A 17 Y 24La Tierra Chaleco 7 A 17 Y 24
La Tierra Chaleco 7 A 17 Y 24
vega95
 
Universidad tecnica de amabato joha ntics
Universidad tecnica de amabato joha nticsUniversidad tecnica de amabato joha ntics
Universidad tecnica de amabato joha ntics
jcaritoavila
 

Destaque (19)

Examen metodo 2 da. unidad
Examen metodo 2 da. unidadExamen metodo 2 da. unidad
Examen metodo 2 da. unidad
 
WTWE.
WTWE.WTWE.
WTWE.
 
E:\EstratificacióN DemográFica Y Social
E:\EstratificacióN DemográFica Y SocialE:\EstratificacióN DemográFica Y Social
E:\EstratificacióN DemográFica Y Social
 
Ejemplosss
EjemplosssEjemplosss
Ejemplosss
 
E:\Mis Documentos\Santiago\Cuarto Ciclo\ComunicacióN Eficas En El Medio Laboral
E:\Mis Documentos\Santiago\Cuarto Ciclo\ComunicacióN Eficas En El Medio LaboralE:\Mis Documentos\Santiago\Cuarto Ciclo\ComunicacióN Eficas En El Medio Laboral
E:\Mis Documentos\Santiago\Cuarto Ciclo\ComunicacióN Eficas En El Medio Laboral
 
Gestion
GestionGestion
Gestion
 
Commmpete por Diana Vinay
Commmpete por Diana VinayCommmpete por Diana Vinay
Commmpete por Diana Vinay
 
Блогирање на долги патеки
Блогирање на долги патекиБлогирање на долги патеки
Блогирање на долги патеки
 
InvestigacióN
InvestigacióNInvestigacióN
InvestigacióN
 
Current and future challenges of the poultry industry
Current and future challenges of the poultry industryCurrent and future challenges of the poultry industry
Current and future challenges of the poultry industry
 
Taller ggb práctica 4
Taller ggb  práctica 4Taller ggb  práctica 4
Taller ggb práctica 4
 
Mis apellidos.pptx
Mis apellidos.pptxMis apellidos.pptx
Mis apellidos.pptx
 
How to mellow the rage
How to mellow the rageHow to mellow the rage
How to mellow the rage
 
e-commerce
e-commercee-commerce
e-commerce
 
La Tierra Chaleco 7 A 17 Y 24
La Tierra Chaleco 7 A 17 Y 24La Tierra Chaleco 7 A 17 Y 24
La Tierra Chaleco 7 A 17 Y 24
 
Ieeepro techno solutions 2013 ieee embedded project dynamic traffic control...
Ieeepro techno solutions   2013 ieee embedded project dynamic traffic control...Ieeepro techno solutions   2013 ieee embedded project dynamic traffic control...
Ieeepro techno solutions 2013 ieee embedded project dynamic traffic control...
 
Do you have any questions for me
Do you have any questions for meDo you have any questions for me
Do you have any questions for me
 
Universidad tecnica de amabato joha ntics
Universidad tecnica de amabato joha nticsUniversidad tecnica de amabato joha ntics
Universidad tecnica de amabato joha ntics
 
4 marginal cost
4 marginal cost4 marginal cost
4 marginal cost
 

Semelhante a Rooster Tech Talk

Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
Tomas Doran
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
Tomas Doran
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
Bill Buchan
 
Black hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slidesBlack hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slides
Bakry3
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
Ruben Tan
 

Semelhante a Rooster Tech Talk (20)

Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
Ansible - A 'crowd' introduction
Ansible - A 'crowd' introductionAnsible - A 'crowd' introduction
Ansible - A 'crowd' introduction
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Webinar: Queues with RabbitMQ - Lorna Mitchell
Webinar: Queues with RabbitMQ - Lorna MitchellWebinar: Queues with RabbitMQ - Lorna Mitchell
Webinar: Queues with RabbitMQ - Lorna Mitchell
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Automation in Cloud
Automation in CloudAutomation in Cloud
Automation in Cloud
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
 
Daemons
DaemonsDaemons
Daemons
 
Wielding a cortana
Wielding a cortanaWielding a cortana
Wielding a cortana
 
Deployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS LinuxDeployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS Linux
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
 
Black hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slidesBlack hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slides
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
 
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Rooster Tech Talk

  • 2. Rooster • It does the same thing everyday at the same time, whether you are sleeping or not
  • 3. Rooster • Designed to run periodic tasks, on schedule
  • 4. History • Previously we used the daemons gem plus the daemon generator plugin. • Headaches: • Each daemon is a separate process. • Not very DRY:
  • 5. Not DRY • Each daemon has two files: • The actual code that runs as a daemon (e.g. network_point_update_daemon.rb) •
  • 6. Not DRY • Each daemon has two files: • And a daemon control script (e.g. network_point_update_daemon_ctl) •
  • 7. Not DRY • The only bit of code that actually does our work: AppUser.daily_amount_grant • The Rails environment is loaded within each daemon process! Not good for memory. • No centralized logging/error handling; poignantly recognized when we wanted exceptions emailed to us. • Management of each daemon process required another entry into monit's config file (eww!):
  • 8. Back To The Future (of scheduled tasks)
  • 11. Rooster What does it do? Scratches the itches of our previous configuration
  • 12. Rooster It’s DRY • One daemon, monitored by monit • One Rails environment, loaded once • Easier management:  TCP server (easily accessed by telnet), rake tasks, more to come... • Centralized and configurable error handling and logging: Rooster::Runner.error_handler = lambda { |e| HoptoadNotifier.notify(e) }
  • 13. How? • Rooster leverages 3 (optionally 4) excellent open source bits of software:
  • 14. How? • Rooster leverages 3 (optionally 4) excellent open source bits of software: • EventMachine:  provides event-driven I/O using the Reactor pattern.  It lets you write network clients and servers without handling sockets.
  • 15. How? • Rooster leverages 3 (optionally 4) excellent open source bits of software: • EventMachine:  provides event-driven I/O using the Reactor pattern.  It lets you write network clients and servers without handling sockets. • Rufus Scheduler:   a Ruby gem for scheduling pieces of code (can leverage EventMachine if available).
  • 16. How? • Rooster leverages 3 (optionally 4) excellent open source bits of software: • EventMachine:  provides event-driven I/O using the Reactor pattern.  It lets you write network clients and servers without handling sockets. • Rufus Scheduler:   a Ruby gem for scheduling pieces of code (can leverage EventMachine if available). • daemons:  A Ruby gem that provides an easy way to wrap existing ruby code to be run as a daemon, and to be controlled by simple start/stop/restart commands.   (I know we moved away from our previous daemons-based solution, but not all daemons are bad).
  • 17. How? • Rooster leverages 3 (optionally 4) excellent open source bits of software: • EventMachine:  provides event-driven I/O using the Reactor pattern.  It lets you write network clients and servers without handling sockets. • Rufus Scheduler:   a Ruby gem for scheduling pieces of code (can leverage EventMachine if available). • daemons:  A Ruby gem that provides an easy way to wrap existing ruby code to be run as a daemon and to be controlled by simple start/stop/restart commands.   (I know we moved away from our previous daemons-based solution, but not all daemons are bad). • Chronic (Optional) - A handy gem for natural language date/ time parsing.
  • 18. How? • These components fit together thusly:
  • 19. How? • These components fit together thusly: • The rooster daemon is started, and then kicks off the Rooster::Runner.
  • 20. How? • These components fit together thusly: • The rooster daemon is started, and then kicks off the Rooster::Runner. • Rooster::Runner runs the main EventMachine reactor loop, loads a Rufus::Scheduler, loads (and optionally schedules) each rooster task, and starts the ControlServer.
  • 21. How? • These components fit together thusly: • The rooster daemon is started, and then kicks off the Rooster::Runner. • Rooster::Runner runs the main EventMachine reactor loop, loads a Rufus::Scheduler, loads (and optionally schedules) each rooster task, and starts the ControlServer. • Rooster::ControlServer is a TCP-based server that listens for Rooster control commands (e.g.  schedule, unschedule, exit, etc.).
  • 22. How? • These components fit together thusly: • The rooster daemon is started, and then kicks off the Rooster::Runner. • Rooster::Runner runs the main EventMachine reactor loop, loads a Rufus::Scheduler, loads (and optionally schedules) each rooster task, and starts the ControlServer. • Rooster::ControlServer is a TCP-based server that listens for Rooster control commands (e.g.  schedule, unschedule, exit, etc.). • Rooster::ControlClient issues commands to the ControlServer; used mainly as a rake helper.
  • 23. I kan haz A EXAMPLE Pleez?
  • 24. Example • I want a task that kills all kittens at 4:20pm every day • > script/generate rooster_task KittenKiller • Generates a new templated task in: RAILS_ROOT/lib/rooster/tasks/kitten_killer_task.rb • rake rooster:launch (and then maybe `rake rooster:start TASK=KittenKillerTask`)
  • 25. Commands • Tag-based commands are handy for controlling only a subset of available tasks • For example, we have separate rooster tasks running on app1 and app3, and are controlled with those server-specific tags.
  • 26. Future Goals • Make rooster task scheduling blocks DRYer, especially by abstracting away the ActiveRecord connection pool cleanup. • Refactor Rooster::Runner (prettier code). • Add scripts (e.g. script/rooster daemon:start) • On daemon launch, autostart tasks having a certain tag (or accept a lambda, e.g. launch_if => lamba { |task| task.tags.include?(“app1”) } )
  • 27. References • http://daemons.rubyforge.org/ • http://github.com/jmettraux/rufus-scheduler/tree/master • http://rubyeventmachine.com/ • http://github.com/findchris/rooster/tree/master
  • 28. The Rooster Has Spoken
  • 30. Single Slide: Create a Rails plugin and push to github • First, go to github.com, signup, add ssh keys, and create a new project • Then...