-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land #12960, add ttl to job results instantiated from an RPC request
- Loading branch information
Showing
9 changed files
with
288 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require 'monitor' | ||
|
||
class JobStateTracker | ||
|
||
include MonitorMixin | ||
|
||
def initialize(result_ttl=nil) | ||
self.ready = Set.new | ||
self.running = Set.new | ||
# Can be expanded upon later to allow the option of a MemCacheStore being backed by redis for example | ||
self.results = ResultsMemoryStore.new(expires_in: result_ttl || 5.minutes) | ||
end | ||
|
||
def waiting(id) | ||
ready << id | ||
end | ||
|
||
def start(id) | ||
running << id | ||
ready.delete(id) | ||
end | ||
|
||
def completed(id, result, ttl=nil) | ||
begin | ||
# ttl of nil means it will take the default expiry time | ||
results.write(id, {result: result}, ttl) | ||
ensure | ||
running.delete(id) | ||
end | ||
end | ||
|
||
def failed(id, error, ttl=nil) | ||
begin | ||
# ttl of nil means it will take the default expiry time | ||
results.write(id, {error: error.to_s}, ttl) | ||
ensure | ||
running.delete(id) | ||
end | ||
end | ||
|
||
def running?(id) | ||
running.include? id | ||
end | ||
|
||
def waiting?(id) | ||
ready.include? id | ||
end | ||
|
||
def finished?(id) | ||
results.exist? id | ||
end | ||
|
||
def result(id) | ||
results.fetch(id) | ||
end | ||
|
||
def delete(id) | ||
results.delete(id) | ||
end | ||
|
||
def results_size | ||
results.size | ||
end | ||
|
||
def waiting_size | ||
ready.size | ||
end | ||
|
||
def running_size | ||
running.size | ||
end | ||
|
||
alias :ack :delete | ||
|
||
private | ||
|
||
attr_accessor :ready, :running, :results | ||
|
||
class ResultsMemoryStore < ActiveSupport::Cache::MemoryStore | ||
def size | ||
@data.size | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
require 'msf/core/rpc/v10/rpc_job' | ||
require 'msf/core/rpc/v10/rpc_db' | ||
|
||
|
||
module Msf | ||
module RPC | ||
|
||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.