Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions deploy/lib/deployTriggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ module.exports = {

deletePreviousTriggersForApplication(application) {
// Delete and re-create every triggers...
const deleteTriggersPromises = application.currentTriggers.map((trigger) =>
this.deleteTrigger(trigger.id)
const deleteTriggersPromises = application.currentTriggers.map(
(trigger) => {
if ("schedule" in trigger) {
this.deleteCronTrigger(trigger.id);
} else {
this.deleteMessageTrigger(trigger.id);
}
}
);

return Promise.all(deleteTriggersPromises);
Expand All @@ -65,12 +71,20 @@ module.exports = {
return [];
}

const createTriggersPromises = serverlessApp.events.map((event) =>
this.createTrigger(application.id, isFunction, {
schedule: event.schedule.rate,
args: event.schedule.input || {},
})
);
const createTriggersPromises = serverlessApp.events.map((event) => {
if ("schedule" in event) {
this.createCronTrigger(application.id, isFunction, {
schedule: event.schedule.rate,
args: event.schedule.input || {},
});
}
if ("nats" in event) {
this.createMessageTrigger(application.id, {
name: event.nats.name,
scw_nats_config: event.nats.scw_nats_config,
});
}
});

return Promise.all(createTriggersPromises);
},
Expand Down
9 changes: 8 additions & 1 deletion docs/events.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: thanks for updating the docs, really appreciated 🙏


With events, you can link your functions with CRON Schedule (time-based) triggers.
With events, you can link your functions with CRON Schedule (time-based) or NATS (message-based) triggers.

To do this you can add an `events` key in your function or container as follows:

Expand All @@ -17,6 +17,13 @@ functions:
input:
key: value
key2: value2
- nats:
name: my-nats-event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think it's possible to include this directly in the top-level message, since all triggers can be given a name:

events:
 - name: my-nats-event
   nats:
     scw_nats_config:
       ...
     

However, it's okay like this, the API doesn't define a clear standard for what's a trigger and I don't reckon it's a big deal.

scw_nats_config:
subject: ">"
mnq_nats_account_id: "nats account id"
mnq_project_id: "project id"
mnq_region: "fr-par"

# Container
custom:
Expand Down
Loading
Loading