mapbox / mapbox/watchbot-progress-py
Customize reduce message
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
The `Part` context manager is in charge of sending the final `reduce` message. But the message
structure is hardcoded; there's no way for the user of `Part` to specify additional data.
We need to give the user more control over the reduce message. Two options so far:
### 1. pass data into `Part` as an argument
```
msg = {'custom': 'hi'}
with Part(..., reduce_message=msg)
pass
```
This has the advantage of being straighforward to understand and a simple implementation.
The downside is that we're forcing the user to construct the message *before* the context block.
It would not allow for constructing the message within the block.
My hunch is that this would be fine for most use cases and probably where we should start.
### 2. send data from the inner block
With some context manager tricks, it is possible for the inner block and the context manager to communicate using `yield` and `gen.send`. The example below proves it *can* be done - but the complexity and obscurity of this approach might be too much.
```python
@contextmanager
def block():
print('before')
msg = yield # wait for a value to be sent
print(f'the inner block sent me {msg}')
yield # run remainder of inner block
print('after')
# Have to instantiate the context manager separate from the with statement
# `with block() as context` will not work
context = block()
with context:
print('inside')
msg = {'custom': 42}
# the inner block MUST send something or we get
# a RuntimeError: generator didn't stop
context.gen.send(msg)
print('still inside the block')
```
which prints
```
before
inside
the inner block sent me 42
still inside the block
after
```
cc @dnomadb @vincentsarago and @sgillies - this context manager / generator hack is a kind of crazy but thought you might enjoy it :-)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Python Part context manager, which currently assembles and sends the final reduce message. Review how the context block and reduce message are connected, then resolve which proposed customization approach the project should support. Done means users can provide additional reduce-message data without breaking existing Part behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100