-
Notifications
You must be signed in to change notification settings - Fork 13
minimal working example with TTL #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
draelos
wants to merge
10
commits into
project-improv:dev
Choose a base branch
from
draeloslab:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
54fe851
minimal working example with TTL
paulawucu c752833
ran black formatter
paulawucu e303dba
more formatting on pytest files
paulawucu 5a41172
sample_generator_exp inherents from sample_generator
paulawucu 6e062f2
added output folders to gitignore
anjshnkr 208c1a1
added output_* folders to gitignore
paulawucu db7cb35
merge project improv updates
paulawucu 30e5b5f
resolved conflict merges,; add TTL
paulawucu fab5b7c
updated yaml and sample generator file to match the new code logics
paulawucu f3e4e6d
Merge branch 'dev' into dev
paulawucu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,53 @@ | ||
| from actors.sample_generator_zmq import Generator | ||
| import numpy as np | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
|
|
||
| class Generator_exp(Generator): | ||
| """Sample actor to generate data to pass into a sample processor with TTL for each Redis key | ||
|
|
||
| Intended for use along with sample_processor.py. | ||
| """ | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| self.data = None | ||
| self.name = "Generator_exp" | ||
| self.frame_num = 0 | ||
|
|
||
| def runStep(self): | ||
| """Generates additional data after initial setup data is exhausted. | ||
|
|
||
| Data is of a different form as the setup data in that although it is | ||
| the same size (5x1 vector), it is uniformly distributed in [1, 10] | ||
| instead of in [1, 100]. Therefore, the average over time should | ||
| converge to 5.5. | ||
| """ | ||
|
|
||
| if self.frame_num < np.shape(self.data)[0]: | ||
| if self.store_loc: | ||
| data_id = self.client.put( | ||
| self.data[self.frame_num], str(f"Gen_raw: {self.frame_num}") | ||
| ) | ||
| else: | ||
| data_id = self.client.put(self.data[self.frame_num], ex=40) | ||
| # logger.info('Put data in store') | ||
| try: | ||
| if self.store_loc: | ||
| self.q_out.put([[data_id, str(self.frame_num)]]) | ||
| else: | ||
| self.q_out.put(data_id) # AsyncQueue.put() | ||
| # logger.info("Sent message on") | ||
|
|
||
| self.frame_num += 1 | ||
| except Exception as e: | ||
| logger.error( | ||
| f"--------------------------------Generator Exception: {e}" | ||
| ) | ||
| else: | ||
| self.data = np.concatenate( | ||
| (self.data, np.asmatrix(np.random.randint(10, size=(1, 5)))), axis=0 | ||
| ) | ||
This file contains hidden or 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,21 @@ | ||
| actors: | ||
| Generator_exp: | ||
| package: actors.sample_generator_expiration | ||
| class: Generator_exp | ||
|
|
||
| Processor: | ||
| package: actors.sample_processor_zmq | ||
| class: Processor | ||
|
|
||
| # connections: | ||
| # Generator.q_out: [Processor.q_in] | ||
|
|
||
| connections: | ||
| Generator-Processor: | ||
| sources: | ||
| - Generator_exp.q_out | ||
| sinks: | ||
| - Processor.q_in | ||
|
|
||
| # redis_config: | ||
| # port: 6370 |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -88,7 +88,7 @@ def connect_to_server(self): | |
|
|
||
| return self.client | ||
|
|
||
| def put(self, object): | ||
| def put(self, object, ex=60): | ||
| """ | ||
| Put a single object referenced by its string name | ||
| into the store. If the store already has a value stored at this key, | ||
|
|
@@ -99,6 +99,7 @@ def put(self, object): | |
| Args: | ||
| object: the object to store in Redis | ||
| object_key (str): the key under which the object should be stored | ||
| ex (int): TTL; the number of seconds after which the object got expired | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. English phrasing: Maybe something like |
||
|
|
||
| Returns: | ||
| object: the object that was a | ||
|
|
@@ -108,7 +109,7 @@ def put(self, object): | |
| pickle.dumps(object, protocol=5), level=self.compression_level | ||
| ) | ||
|
|
||
| self.client.set(object_key, data, nx=True) | ||
| self.client.set(object_key, data, nx=True, ex=ex) | ||
|
|
||
| return object_key | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only line we're changing relative to the other generator? Could we not inherit and overload the one method? Just seems like a lot of code duplication.