Chef has unique abstraction and processing models. Until you understand them, it is easy to write buggy recipes.
The most important thing to understand is the following: a Chef recipe is not a collection of scripts.
Chef Processing Model
function replaceDoc(html) { | |
var newDoc = document.open("text/html", "replace"); | |
newDoc.write(html); | |
newDoc.close(); | |
} |
2014-01-31T08:25:13.684816+00:00 app[analytics.1]: ** [NewRelic][01/31/14 08:25:13 +0000 213b2cc6-fb96-4c1a-b031-9edexxxxxxxx (2)] WARN : Error during check_for_and_handle_agent_commands, will retry later: | |
2014-01-31T08:25:13.684816+00:00 app[analytics.1]: ** [NewRelic][01/31/14 08:25:13 +0000 213b2cc6-fb96-4c1a-b031-9edexxxxxxxx (2)] WARN : NewRelic::Agent::ServerConnectionException: Service unavailable (503): Service Unavailable |
require 'open-uri' | |
require 'json' | |
API = 'https://api.github.com/users/swoop-inc/repos' | |
open(API) do |io| | |
puts JSON.parse(io.read). | |
reject { |repo| repo['fork'] }. | |
map { |repo| repo['full_name'] }. | |
to_json |
class ChoiceSequence | |
MAX_CHOICES = 26 | |
MAX_SEQUENCE_LENGTH = 25 | |
FACTORIAL = (1..MAX_SEQUENCE_LENGTH).reduce([1]) do |memo, n| | |
memo << memo.last * n | |
end.freeze | |
def self.position(seq) | |
length = seq.length |
# Syntax sugar | |
class ArrayValidator < EnumValidator | |
end |
# ADD LOCAL CONFIGURATION HERE | |
[user] | |
name = Simeon Simeonov | |
email = sim@fastignite.com | |
[core] | |
editor = mate -w | |
excludesfile = /Users/sim/.gitignore_global |
def publish(data) | |
configure | |
conn = Bunny.new(connection_uri).start | |
channel = conn.create_channel | |
queue = channel.queue(queue_name, durable: true) | |
exchange = channel.direct(exchange_name, durable: true) | |
log_data(data) | |
exchange.publish(data, :routing_key => queue.name) | |
queue_status(queue.status) | |
rescue Exception => e |
task :cache_size => :environment do | |
require 'objspace' | |
def calc_overhead(run, count) | |
cache = ActiveSupport::Cache.lookup_store :memory_store, size: 128.gigabytes | |
# keep all key/value pairs unique | |
cache.instance_variable_get(:'@data').compare_by_identity | |
GC.start | |
before = ObjectSpace.count_objects_size({})[:TOTAL] |