-
Notifications
You must be signed in to change notification settings - Fork 261
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
trigger
crate
#402
Comments
I can create a trigger trait. This will help me to work on the CloudEvents trigger feature |
I am thinking about merging the two triggers, HTTP and Redis, to one crate called #[async_trait]
pub trait Trigger<T> {
pub async fn new(
builder: Builder<T>,
app: Application<CoreComponent>,
config: TriggerConfig<T>,
) -> Result<Self>;
async fn run(&self) -> Result<()>;
} and changes how we import triggers: use spin_trigger::{HttpTrigger, RedisTrigger, CloudEventTrigger};
use spin_engine::{Builder, ExecutionContextConfiguration};
fn main() {
...
let builder = self.prepare_ctx_builder(app.clone()).await?;
let trigger = HttpTrigger::new(builder, app, self.opts.address, tls).await?;
trigger.run().await?;
} The benefits of doing this are
Let me know your thoughts @lann @radu-matei |
I agree with having a crate that contains the common logic between the triggers, but not sure with merging our triggers into this crate. Unless you are thinking about something else with merging the existing triggers? What do you think? |
I haven't put a ton of thought into this yet, but I was vaguely thinking that the Lines 158 to 172 in ad51cdd
Ideally we could also come up with generic versions of some of these (and anything else that makes sense!): Lines 70 to 82 in ad51cdd
Lines 225 to 234 in ad51cdd
Lines 327 to 336 in ad51cdd
|
I'd also be happy if we could better decouple triggers from the |
Thanks for the pointers @lann @radu-matei I was looking at the http trigger and redis trigger impl and didn't find too many common ground. Their usage of But @lann 's code blocks make sense. I will make a draft PR today and let you to review it. |
I am trying to define |
No problem! We don't need to boil the ocean all at once here. |
@Mossaka I have time today to take a look at this; if you would like we could work together on supporting what you need for a CloudEvents trigger? |
I think something like this should be feasible: https://github.com/fermyon/spin/pull/415/files#diff-52052d5f095ea9072b1d41ab7754a0b4479f7340f8bedd9da41f8575f380150e |
This could be relevant, depending on timing: #417 |
Fixed by #418 |
Spin currently has two built-in trigger types:
HttpTrigger
andRedisTrigger
. There is also aTimerTrigger
example and ongoing work towards new cron / "Schedule" (#365) and "CloudEvents" (#394) triggers.These triggers - especially the two built-in types - share some common logic in how they prepare and invoke their handler components. In order to reduce duplication and future divergence, we should extract that commonality into a new
trigger
crate that exposes trait(s) that can be implemented by individual trigger types.The text was updated successfully, but these errors were encountered: