sjordan's avatar

Dispatching Jobs to a RESTful Lumen Queue System?

I am working with an older version of Codeigniter. Longer term, I'd like to port to Laravel.

However, the short term I need to process tasks such a sending emails, processing files uploads, interacting with 3rd party API; all things that are best handled with task queues.

For example, when a user creates an account, I might want to get the latitude and longitude of his business address using Google API. There is no reason the user should have to wait for my server to connect to Google, receive the request and process it. Let alone, be subject to potential issues such as API down, API authentication failed, etc.

The ideal scenario would be to create a job -- "get lat-long" and throw it on a queue. A worker work periodically poll for jobs and when processed successfully, the user's details would be silently updated or on failure, a log entry would be created for future investigation.

I'm thinking I could create a simple Lumen app to implement my queue (https://lumen.laravel.com/docs/master/queues)

As the Lumen app would be independent of the existing app, I'm thinking the Lumen app would be a REST implementation.

This brings me to my question, the Lumen documentation mentions adding dispatching jobs to the queue via dispatch(new ExampleJob) or Queue::push(new ExampleJob). These approaches assumes queue and caller are the same app.

Can someone provide pointers for dispatching via REST? And what the message object might need to look like in this instance?

Thank you

0 likes
2 replies
jekinney's avatar

Rest should self explanatory as it's a pattern.

What apis that I have built and utilize that trigger long running process send back a code of 202 accepted immediately when accepted (validation etc ran).

Then the process is run.

If you need verification that a process is done, you can implement web hooks. Which is just an API that sends data to listening routes. This way you can keep data in sink.

Say your email.

User registers, after all set you send aplicable user data you your API. It verifies the data and replies 202.

Your main app goes on about its business. Then after lumen process the request sends a success webhook with applicable data (if any). Maybe to set a Boolean on the user to true an email sent.

You don't nessesarly have to queue anything on the lumen app.

Please or to participate in this conversation.