Skip to content

Commit

Permalink
update gems, dummy db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifiht committed Sep 11, 2024
1 parent 9b94787 commit a921f60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ gem "http"
gem "rake"
gem "rufo"
gem "pp"
gem "pg"
#gem 'rice' -- this is for torch-rb
#gem 'torch-rb' -- to be added later
51 changes: 11 additions & 40 deletions src/modules/database/database.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
#=============<[ Gems ]>=============#
require "sqlite3"
require "spriggan"
require "pg"
require "redfairy"

#=============<[ Local Vars ]>================#
core_config = RedFairy.new("shikigami")

#=============<[ Instance Vars ]>=============#
@cwd = %x(pwd).chomp
@beanstalk_host = core_config.get("beanstalk_host")
@beanstalk_port = core_config.get("beanstalk_port")
@redis = Redis.new(host: "10.0.1.1", port: 6380, db: 15)
#=============<[ Experimental ]>=============#
@db_user = core_config.get("db_user")
@db_pass = core_config.get("db_pass")

@sprig = Spriggan.new(
beanstalk_host: @beanstalk_host,
beanstalk_port: @beanstalk_port,
module_name: "database",
)
query = File.read('./init_pgre.sql')

#=============<[ Methods ]>==================#
# Evaluates a string and logs to PM2 on error
def eval_string(str)
begin
eval str
rescue SyntaxError
@sprig.pm2_log("SyntaxError: #{str}")
rescue NameError
@sprig.pm2_log("NameError: #{str}")
end #begin
end #def

#============================================#
#+++----- <[ Main Body ]> -----+++#
#============================================#
@sprig.add_thread {
loop do
msg_hash = @sprig.get_msg
begin
eval_string(msg_hash["msg"])
rescue Exception => e
@sprig.pm2_log("Rescued job: #{e}")
end #begin
end #loop
}

#[[[[[[ RUN THREADS ]]]]]]
@sprig.run
conn = PG.connect( host: 'localhost', port: '5435', dbname: 'test1', user: @db_user, password: @db_pass )
conn.exec( query ) do |results|
results.each do |row|
puts row.inspect
end
end

0 comments on commit a921f60

Please sign in to comment.