-
Notifications
You must be signed in to change notification settings - Fork 11
Middlewares
akshat edited this page Nov 7, 2022
·
5 revisions
Goose has provision for middlewares which can run before/after execution of a Job.
-
middleware-fn
takesnext
as input - It returns a function of arity 2
- Returned function takes
opts
&job
as inputs - Function calls
next
withopts
&job
- Function can modify
opts
/job
before proceeding, with utmost care - Function may choose to act on the result of
next
or not call it altogether based on certain criteria
- Modify args of job pre-execution
- Use returned value of job post-execution
- Ignore exceptions thrown by job
- Extending Goose's functionalities as described in this issue
(defn my-middleware
[next]
(fn [opts job]
; Be careful when modifying fields of opts/job.
(let [result (next opts job)]
(log/info result))))
(w/start (assoc w/default-opts :middlewares my-middleware))
- Middleware's time will be added to job execution time
- For client-side middlewares, you can wrap enqueuing function around your middleware
Previous: Guide to Custom Metrics Backend Next: API
Home | Getting Started | RabbitMQ | Redis | Error Handling | Monitoring | Production Readiness | Troubleshooting
Need help? Open an issue or ping us on #goose @Clojurians slack.