Comments (6)
@padi: Congratulations! You have taken LightService much farther than I have.
Why not handling the exception in the actions right away and failing the context with set_failure!
in the rescue block? I am not a big fan of bubbling up the exception to the very top and handling it there.
So in the code you'd do this:
class SomeAction
include LightService::Action
executed do |context|
begin
# do some action
rescue AnotherError => e
# do something unique
context.set_failure! "unique message"
end
end
end
Do you think this would work?
from light-service.
I guess I have to supply more info regarding our use case (updated the SomeOrganizer class to reflect that the organizer is a resque job)
Consider the following:
- We're making use of Resque's failure backend feature to handle our errors. With that, it is imperative that we
raise
errors to be able to send it to multiple backends, e.g. notify developers via email that some error occurred and record the failure on redis at the same time. - We want to make sure that the error messages supply helpful information, e.g. along with the error, send the id of specific record when the error occurred, so we re-
raise
the error with a custom message. - Typically, we have 10 or more actions in one organizer, half of which are dealing with having to communicate to multiple APIs (using a different client gem for each api).
So to answer your question, we've been using that route and there can be a problem with that:
It does not enforce the rescue for all actions that should rescue the same type of custom error. Our specific error was an error raised by a 3rd party client gem that's used in multiple steps. If someone adds an action that uses the same gem, and forgets to add begin...rescue
(which indeed happens sometimes), and an error happens, no one is notified that an error occurred and nothing is recorded (except probably in the logs).
Instead of writing the error catching logic once-and-for-all, we end up having to remember that whenever we have to deal with this client gem in a new action, we should include this begin-end logic.
I'm not keen on writing code for this until I figure out for myself that this is indeed a feature needed by LightService. If this is too special for a use case, I might have to create another gem, e.g. light-service-resque
or something like that.
from light-service.
Why don't you have a facade for the external library? That way the facade could handle the exceptions.
Anyway, since this is an additive change I would have no problem to include this in the project. I think what you propose is clean and elegant.
We just need to make sure this feature is clearly documented in the wiki.
Thanks!
from light-service.
@padi: Are you working on this? Can I close this issue?
from light-service.
@adomokos not at the moment. Just used ActiveSupport::Rescueable
instead. Closing.
from light-service.
Thanks!
from light-service.
Related Issues (20)
- Is there a LightService-like project in Python? HOT 2
- Yard Documentation to code write with light-service HOT 4
- Deprecation warning using organizer within an organizer HOT 7
- Rollback Block Not Invoked In Iterated Actions HOT 10
- Testing actions in isolation HOT 4
- [RFC] Closing pull requests while a new build is starting causes failures HOT 1
- Running actions in jobs HOT 11
- reusing modules within actions
- Surprising `add_to_context` orchestrator behaviour HOT 1
- How to handle default values for dependency injection? HOT 9
- Help testing LS release candidate HOT 6
- Why this gem add activesupport as runtime dependency? HOT 11
- around for Actions HOT 3
- Namespacing Organizers and Actions HOT 1
- Confused about context failure HOT 1
- Can I chain Organizers together? HOT 5
- `reduce_case` not supported when running Ruby < 2.7, but not documented as such HOT 1
- README's built-in localization adapter documentation has a bug
- How about an "after" hook that will be called after "fail_and_return!"? HOT 2
- Remove the ActiveSupport dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from light-service.