Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/simple_map_reduce/server/job_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class JobTracker < Sinatra::Base
(params[:worker_size].to_i.zero? ? 1 : params[:worker_size].to_i.abs),
MAX_WORKER_RESERVABLE_SIZE
].min
reserved_workers = []
begin
reserved_workers = self.class.fetch_available_workers(worker_size)
json(succeeded: true, reserved_workers: reserved_workers.map(&:dump))
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_map_reduce/server/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def dump
# @options attributes [String] event
def update!(attrs = {})
# Handle both hash and keyword arguments
attrs = attrs.is_a?(Hash) ? attrs : { url: nil, event: nil }
attrs = attrs.is_a?(Hash) ? attrs : { event: attrs }
url = attrs[:url]
event = attrs[:event]

Expand Down
23 changes: 23 additions & 0 deletions spec/server/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

RSpec.describe SimpleMapReduce::Server::Worker do
let(:worker) { build(:worker) }

describe '#update!' do
context 'when called with an event symbol' do
it 'updates the state accordingly' do
expect(worker.state).to eq(:ready)
worker.update!(:reserve)
expect(worker.state).to eq(:reserved)
end
end

context 'when called with a hash of attributes' do
it 'updates the state based on the :event key' do
worker.update!(event: :reserve)
worker.update!(event: :work)
expect(worker.state).to eq(:working)
end
end
end
end
Loading