Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created May 25, 2011 10:32
Show Gist options
  • Select an option

  • Save timruffles/990749 to your computer and use it in GitHub Desktop.

Select an option

Save timruffles/990749 to your computer and use it in GitHub Desktop.

Revisions

  1. timruffles revised this gist May 25, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion aop_logging.rb
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,8 @@ def process_message message
    process_message do
    before { "Started #{message.headers["message-id"]}" }
    after { "Finished #{message.headers["message-id"]}" }
    method ['PassingGame::Entry','count_active_for'], lambda { "#{active_entries} active entries for match_id = #{match_id}" }
    method ['PassingGame::Entry','count_active_for'], :after, lambda { "#{active_entries} active entries for match_id = #{match_id}" }
    method ['JSON','parse'], :after, lambda { logger.debug "Action: #{event['action']}" }
    end
    end

  2. timruffles created this gist May 25, 2011.
    37 changes: 37 additions & 0 deletions aop_logging.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    before:

    def process_message message
    logger.debug "Started #{message.headers["message-id"]}"
    event = JSON.parse message.body
    logger.debug "Action: #{event['action']}"
    match_id = event['matchID']
    active_entries = PassingGame::Entry.count_active_for match_id
    logger.info "#{active_entries} active entries for match_id = #{match_id}"
    if fail_on? event
    fail_entries_for match_id
    else
    give_points_to_entries_for match_id
    end
    logger.debug "Finished #{message.headers["message-id"]}"
    end

    after:

    log do
    process_message do
    before { "Started #{message.headers["message-id"]}" }
    after { "Finished #{message.headers["message-id"]}" }
    method ['PassingGame::Entry','count_active_for'], lambda { "#{active_entries} active entries for match_id = #{match_id}" }
    end
    end

    def process_message message
    event = JSON.parse message.body
    match_id = event['matchID']
    active_entries = PassingGame::Entry.count_active_for match_id
    if fail_on? event
    fail_entries_for match_id
    else
    give_points_to_entries_for match_id
    end
    end