<commit_before>#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'base64'

#add script's dir to require path
$: << File.expand_path(File.dirname(__FILE__))+'/../lib/'
require 'sender'
require 'apncore'

# properly close all connections and sokets
Signal.trap("TERM") do
  APNs4r::Sender.closeConnection
  EventMachine::stop_server $server
  puts "#{Time.now.to_s} SendServer stopped"
  exit
end


module SendServer
  def post_init
    puts "-- #{Time.now.to_s} -- Incoming connection"
  end

  def receive_data data
    # TODO store notifications for later batch transmission
    # only when some scaling needed
    notification = Marshal.load( Base64.decode64(data))
    APNs4r::Sender.send notification
    puts "#{Time.now.to_s} #{notification.payload}"
  end
<commit_msg>handling Ctrl+C<commit_after>#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'base64'

#add script's dir to require path
$: << File.expand_path(File.dirname(__FILE__))+'/../lib/'
require 'sender'
require 'apncore'

# properly close all connections and sokets
def stop
  APNs4r::Sender.closeConnection
  EventMachine::stop_server $server
  puts "#{Time.now.to_s} SendServer stopped"
  exit
end
Signal.trap("TERM") {stop}
Signal.trap("INT") {stop}


module SendServer
  def post_init
    puts "-- #{Time.now.to_s} -- Incoming connection"
  end

  def receive_data data
    # TODO store notifications for later batch transmission
    # only when some scaling needed
    notification = Marshal.load( Base64.decode64(data))
    APNs4r::Sender.send notification
    puts "#{Time.now.to_s} #{notification.payload}"
  end

{'fraction_non_alphanumeric': 0.11771919068056406, 'fraction_numerical': 0.009809932556713672, 'mean_word_length': 4.3861386138613865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4366067', 'n_tokens_mistral': 536, 'n_tokens_neox': 521, 'n_words': 143}