Skip to content

Commit

Permalink
Refactor: extract error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Jul 9, 2013
1 parent e235819 commit 08cae13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 0 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ if RUBY_ENGINE == 'ruby'
Cane::RakeTask.new(:quality) do |cane|
cane.style_glob = "lib/**/*.rb"
cane.abc_max = 16
cane.abc_exclude = %w[
Plines::Lua#complete_job
]
cane.no_doc = true
cane.add_threshold 'coverage/coverage_percent.txt', :>=, 100
end
Expand Down
16 changes: 10 additions & 6 deletions lib/plines/lua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def complete_job(job_batch, qless_job)
job_batch.pipeline.configuration.data_ttl_in_milliseconds,
Time.now.getutc.iso8601
rescue Qless::LuaScriptError => e
handle_complete_job_lua_error(qless_job, job_batch, e)
end

private

def call(command, *args)
script.call(command, Time.now.to_i, *args)
end

def handle_complete_job_lua_error(qless_job, job_batch, e)
if e.message.start_with?('JobNotPending')
raise JobBatch::JobNotPendingError, "Jid #{qless_job.jid} cannot be " +
"marked as complete for job batch #{job_batch.id} since it is " +
Expand All @@ -32,12 +42,6 @@ def complete_job(job_batch, qless_job)
end
end

private

def call(command, *args)
script.call(command, Time.now.to_i, *args)
end

def self.lua_table_from(klass)
items = klass.declared_redis_object_names.map { |i|
%Q|"#{i}"|
Expand Down

0 comments on commit 08cae13

Please sign in to comment.