To answer my own question: I'm now running this combination in production since ~12 hours, so far looking good.
Does horizon support enqueuing jobs from non-horizon codebases via illuminate/queue?
Hi, I'm running Laravel Horizon from a typical Laravel based project.
I've a unique challenge that I've a separate / old / legacy code base which is totally non-Laravel.
I currently enqueue jobs from the non-Laravel code base to Laravel via an internal HTTP endpoint which simply dispatched the jobs (I pass the class name and args via JSON responses and the job is simply constructed and dispatched).
However I'm not happy with this approach (dependency on HTTP endpoint) and also start getting performance considerations due do the HTTP overhead and the increased amount of jobs being dispatched. Rather I would prefer to "somehow" enqueue jobs directly from the non-Laravel codebase to the Laravel codebase via Redis.
Spoiler: I got it already working by requiring these packages: illuminate/queue:^6.0 illuminate/redis:^6.0 predis/predis:^1.1
The how-to is quite well explained at https://github.com/illuminate/queue
As long as I keep "mirror job classes" in the non-Laravel repository, I can just do it like this: $queue->pushOn('nameOfQueue', new WhateverJob($args…
and I see them getting processed in the Laravel repository as regular queue jobs.
However I realized: they are only seen and treated as pure "queue" jobs, i.e. it seems to me Horizon is not aware of them at all. I do not use advanced features of Horizon, I just use it's nice config way of handling queues and that's it. Single server, single instance.
My testing so far indicated: it is working. The queues I defined in Horizon are picking up the jobs dispatched from the non-Laravel project correctly.
The ultimate goal is to reduce the non-Laravel code base and move over stuff, but I'm not there yet.
My question is: does anyone know if this is "supported / supposed to work"?
Is there anything else I would need to be aware of?
The only difference I found so far: each job contains an internal id field: the ones generated from the Horizon code base are sequentially numbered, the ones via regular queue have random-looking shapes, i.e.
// horizon
[2020-01-20T07:09:31.345695+00:00] local.INFO: Illuminate\Queue\Events\JobProcessing {"name":"App\Jobs\TestJob","id":"19","attempts":0,"maxTries":null,"timeout":null} {"process_id":1894}
[2020-01-20T07:09:31.349981+00:00] local.INFO: Illuminate\Queue\Events\JobProcessed {"name":"App\Jobs\TestJob","id":"19","attempts":0,"maxTries":null,"timeout":null} {"process_id":1894}
// regular queue (non-laravel project)
[2020-01-20T06:49:11.364529+00:00] local.INFO: Illuminate\Queue\Events\JobProcessing {"name":"App\Jobs\TestJob","id":"8gidMkf94CC8sKCmOJuuMhSycbKN79H7","attempts":0,"maxTries":null,"timeout":null} {"process_id":1894}
[2020-01-20T06:49:11.414342+00:00] local.INFO: Illuminate\Queue\Events\JobProcessed {"name":"App\Jobs\TestJob","id":"8gidMkf94CC8sKCmOJuuMhSycbKN79H7","attempts":0,"maxTries":null,"timeout":null} {"process_id":1894}
thanks
Over 24 hours, it's still running 👍
I guess this answers my question whether this works or not 😀
I still wish I could make the jobs be properly realized by Horizon, but besides reverse engineering this it would require installing Horizion which doesn't work. Horizon requires the Laravel Application which is the service container + stuff on top of it, which isn't available when just using the illuminate/* packages.
Please or to participate in this conversation.