Skip to content

Instantly share code, notes, and snippets.

View kennethkalmer's full-sized avatar

Kenneth Kalmer kennethkalmer

View GitHub Profile
# This task will only be ran once
task :foo do
unless fetch(:foo_completed, false) do
run "whoami"
set(:foo_completed, true)
end
end
INSTRUCTIONS FOR USE
====================
Generate the nanite agent
$ daemon_kit /path/to/daemon -i nanite_agent
Copy the above google.rb into lib/actors/
Open libexec/daemon-daemon.rb and register the actor:
A testament [1] to Handsoap [2], while rewriting the postini gem [3]. This is from git log
$ git log --stat 2f91d4d6eaa8bd76c188f20929a19e456d1bb52e..HEAD | grep changed
2 files changed, 15 insertions(+), 4 deletions(-)
1 files changed, 38 insertions(+), 0 deletions(-)
2 files changed, 282 insertions(+), 1 deletions(-)
1 files changed, 1 insertions(+), 1 deletions(-)
12 files changed, 9 insertions(+), 682 deletions(-)
1 files changed, 1 insertions(+), 0 deletions(-)
8 files changed, 184 insertions(+), 3883 deletions(-)
kenneth@jenny ~/tmp/dk/crond $ ./bin/crond start
kenneth@jenny ~/tmp/dk/crond $ ./bin/crond start
Process already running with id 28197
kenneth@jenny ~/tmp/dk/crond $ ./bin/crond start
Process already running with id 28197
#
# The code below is lifted from a daemon generated with daemon-kit.
#
# It is responsible for executing various commands on Linux servers to provision
# and manage hosting services for several hundred clients on each server. Messages
# are delivered to 'identity'-based queues, where each agent can tune into more than
# one queue depending on that services they offer.
#
# The original messages are JSON objects, representing workitems for the
# ruote workflow engine. There is some intermediary code that slices up the workitems
#
# AMQP generated daemon (this would be the file in libexec/)
#
# NOTE 1: This config would be adapted to be more ruote-friendly
#
# NOTE 2: This would be the names of queues used in the process definition, or JID's to use
#
# NOTE 3: This would be responsible for handling the processesing
#
@kennethkalmer
kennethkalmer / daemon-kit-engine.rb
Created July 10, 2009 22:19
Example for using ruote & daemon-kit together
#
# Requirements:
# * ruote-2.1.10 or later
# * ruote-amqp-2.1.10 or later
# * daemon-kit-0.1.8rc3 or later
#
require 'rubygems'
require 'ruote'
#
# Somewhere in a daemon where activerecord is being used
#
class MyARDaemon
include DaemonKit::ActiveRecord
def something_ar
MyModel.find(:all)
#
# daemon-kit stack configuration
#
# severe pseudo-code example
#
#
# config/environment.rb (shared stack)
#
DaemonKit::Initializer.run do |config|
class CrazyIdea < OpenWFE::ProcessDefinition
sequence do
_loop :break_if => "${f:completed}" do
# This is the queue, getting popped by a REST call. The person who did the pop
# will have the workitem field 'winner_of_the_lock' set to their details, so the
# next participant is dynamic based on that field value.
queue_participant
#
participant "${f:winner_of_the_lock}", :timeout => '1d'