lib/dynflow/dispatcher/client_dispatcher.rb in dynflow-1.3.0 vs lib/dynflow/dispatcher/client_dispatcher.rb in dynflow-1.4.0
- old
+ new
@@ -1,11 +1,12 @@
+# frozen_string_literal: true
module Dynflow
module Dispatcher
class ClientDispatcher < Abstract
TrackedRequest = Algebrick.type do
- fields! id: Integer, request: Request,
+ fields! id: String, request: Request,
accepted: Concurrent::Promises::ResolvableFuture, finished: Concurrent::Promises::ResolvableFuture
end
module TrackedRequest
def accept!
@@ -31,11 +32,11 @@
# seen for the last time. This class can be used to query this
# information and determine whether the record is "fresh enough"
# or whether the Ping really needs to be sent.
class PingCache
# Format string used for formating and parsing times
- TIME_FORMAT = '%Y-%m-%d %H:%M:%S.%L'.freeze
+ TIME_FORMAT = '%Y-%m-%d %H:%M:%S.%L'
DEFAULT_MAX_AGE = 60
# Formats time into a string
#
# @param time [Time] the time to format
@@ -103,11 +104,11 @@
end
attr_reader :ping_cache
def initialize(world, ping_cache_age)
@world = Type! world, World
- @last_id = 0
+ @last_id_suffix = 0
@tracked_requests = {}
@terminated = nil
@ping_cache = PingCache.new world, ping_cache_age
end
@@ -195,10 +196,11 @@
log(Logger::ERROR, e)
Dispatcher::UnknownWorld
end
def track_request(finished, request, timeout)
- id = @last_id += 1
+ id_suffix = @last_id_suffix += 1
+ id = "#{@world.id}-#{id_suffix}"
tracked_request = TrackedRequest[id, request, Concurrent::Promises.resolvable_future, finished]
@tracked_requests[id] = tracked_request
@world.clock.ping(self, timeout, [:timeout, id]) if timeout
yield tracked_request
rescue Dynflow::Error => e