Skip to content

Commit e2be918

Browse files
committed
Specify names for each repeating task
1 parent ea5bde5 commit e2be918

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

lib/ldclient-rb/impl/big_segments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(big_segments_config, logger)
2424

2525
unless @store.nil?
2626
@cache = ExpiringCache.new(big_segments_config.context_cache_size, big_segments_config.context_cache_time)
27-
@poll_worker = RepeatingTask.new(big_segments_config.status_poll_interval, 0, -> { poll_store_and_update_status }, logger)
27+
@poll_worker = RepeatingTask.new(big_segments_config.status_poll_interval, 0, -> { poll_store_and_update_status }, logger, 'LD/BigSegments#status')
2828
@poll_worker.start
2929
end
3030
end

lib/ldclient-rb/impl/repeating_task.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
module LaunchDarkly
66
module Impl
77
class RepeatingTask
8-
def initialize(interval, start_delay, task, logger)
8+
attr_reader :name
9+
10+
def initialize(interval, start_delay, task, logger, name)
911
@interval = interval
1012
@start_delay = start_delay
1113
@task = task
1214
@logger = logger
1315
@stopped = Concurrent::AtomicBoolean.new(false)
1416
@worker = nil
17+
@name = name
1518
end
1619

1720
def start
@@ -30,9 +33,9 @@ def start
3033
sleep(delta)
3134
end
3235
end
33-
end.tap do |worker|
34-
worker.name = "LD/Impl/RepeatingTask"
3536
end
37+
38+
@worker.name = @name
3639
end
3740

3841
def stop

lib/ldclient-rb/impl/store_client_wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def monitoring_enabled?
9999

100100
@logger.warn("Detected persistent store unavailability; updates will be cached until it recovers.")
101101

102-
task = Impl::RepeatingTask.new(0.5, 0, -> { self.check_availability }, @logger)
102+
task = Impl::RepeatingTask.new(0.5, 0, -> { self.check_availability }, @logger, 'LD/StoreWrapper#check_availability')
103103

104104
@mutex.synchronize do
105105
@poller = task

lib/ldclient-rb/polling.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(config, requestor)
1313
@initialized = Concurrent::AtomicBoolean.new(false)
1414
@started = Concurrent::AtomicBoolean.new(false)
1515
@ready = Concurrent::Event.new
16-
@task = Impl::RepeatingTask.new(@config.poll_interval, 0, -> { self.poll }, @config.logger)
16+
@task = Impl::RepeatingTask.new(@config.poll_interval, 0, -> { self.poll }, @config.logger, 'LD/PollingDataSource')
1717
end
1818

1919
def initialized?

spec/impl/repeating_task_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ def null_logger
1111
double.as_null_object
1212
end
1313

14+
it "can name the task" do
15+
signal = Concurrent::Event.new
16+
task = RepeatingTask.new(0.01, 0, -> { signal.set }, null_logger, "Junie B.")
17+
18+
expect(task.name).to eq("Junie B.")
19+
task.stop
20+
end
21+
1422
it "does not start when created" do
1523
signal = Concurrent::Event.new
16-
task = RepeatingTask.new(0.01, 0, -> { signal.set }, null_logger)
24+
task = RepeatingTask.new(0.01, 0, -> { signal.set }, null_logger, "test")
1725
begin
1826
expect(signal.wait(0.1)).to be false
1927
ensure
@@ -23,7 +31,7 @@ def null_logger
2331

2432
it "executes until stopped" do
2533
queue = Queue.new
26-
task = RepeatingTask.new(0.1, 0, -> { queue << Time.now }, null_logger)
34+
task = RepeatingTask.new(0.1, 0, -> { queue << Time.now }, null_logger, "test")
2735
begin
2836
last = nil
2937
task.start
@@ -62,7 +70,7 @@ def null_logger
6270
stopped.set
6371
end
6472
},
65-
null_logger)
73+
null_logger, "test")
6674
begin
6775
task.start
6876
expect(stopped.wait(0.1)).to be true

0 commit comments

Comments
 (0)