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}"
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.
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).
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.
#!/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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With