Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby script 'Killed'

I am running a ruby script from the command line. The script downloads a file (15 MB), unzips it, parses it as JSON and then populates a mysql db with it.

When I run it, I get a simple 'Killed' message back. What's going on? How can I find out what the problem is?

I am using it on an EC2 micro instance.

Thanks

Here's the script

require 'open-uri'
require 'zlib'
require 'json'

require_relative '../db/db.rb'

dl = open('........')
ex = Zlib::GzipReader.new dl
json = JSON.parse ex.read
events = json['resultsPage']['results']['event']

puts "starting to parse #{events.count} event(s)..."
created = 0
updated = 0

events[1..10].each do |event|
    performances = event['performance']
    performances.each do  |performance|
        ar_show = Show.find_or_initialize_by_songkick_id performance['id']
        ar_show.artist_name = performance['displayName']
        ar_show.new_record? ? created += 1 : updated += 1
        ar_show.save!
    end
end

Import.create :updated => updated, :new => created
puts "complete. new: #{created}   -   updated: #{updated}"
like image 249
0xSina Avatar asked Dec 21 '12 00:12

0xSina


People also ask

How do I stop a Ruby script in terminal?

Or you can force a quit “kill” by pressing: “Ctrl” & “C” at the same time. That is all for me for now. Hope this helped you get started or get back to running ruby files within your terminal.

How to terminate a process in Ruby using kill method?

In order to terminate a process in Ruby you can use the kill method in the of the Process class in the following way: If you are using Ruby on Windows you have probably already noticed that Process.kill does not work correctly. When it kills a process with Process.kill ("KILL", pid) the process incorrectly returns status 0 (success).

What is Ruby scripting language?

Ruby is a powerful scripting language. Scripts can be used to automate tasks such as creating and searching files and managing and organizing subdirectories. Companies like Github, Chef and Puppet use Ruby for scripting. Devops teams use scripting to combine development and operations.

How do I run a Ruby program from the command line?

#!/usr/bin/ruby puts "Hello world!" We can run this script in the command line by going to the directory where the file lives and typing in ruby hello.rb. The output of the program will be "Hello world!" Let’s take a look at the content of the script itself.

Is term an invalid argument when killing a process in Ruby?

If you are using Ruby on Windows you have probably already noticed that Process.kill does not work correctly. When it kills a process with Process.kill ("KILL", pid) the process incorrectly returns status 0 (success). Windows complains that TERM is an invalid argument, although Signal.list includes TERM:


1 Answers

You are almost certainly running out of memory, as a micro instance doesn't have much memory or swap space available. I've had this happen with Perl programs. Dynamic languages can use a lot of memory when processing large chunks of data.

The best way to test this theory is to spin up a small or large instance for under an hour (so you won't pay much for it) and try the script there. If it runs, you know that a micro instance is too small for your program to run on.

like image 152
Charles Engelke Avatar answered Sep 20 '22 14:09

Charles Engelke