Skip to content

Instantly share code, notes, and snippets.

@jeystaats
Last active October 3, 2022 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeystaats/380505ed92235675c30cd82d0ceb0dea to your computer and use it in GitHub Desktop.
Save jeystaats/380505ed92235675c30cd82d0ceb0dea to your computer and use it in GitHub Desktop.
Add to Laravel Queue (Redis) from NodeJS [Laravel > 9 )
import { createClient } from 'redis';
import { serialize } from 'php-serialize';
const RedisClient = createClient();
export class Job {
job = null;
connection = null;
queue = null;
chainConnection = null;
chainQueue = null;
delay = null;
middleware = [];
chained = [];
constructor(obj) {
if (obj) {
Object.assign(this, obj);
}
}
}
async function dispatch(name, payload) {
const command = serialize(payload, {
'App\\Jobs\\TestJob': Job,
});
const data = {
job: 'Illuminate\\Queue\\CallQueuedHandler@call',
data: {
commandName: name,
command,
},
timeout: null,
uuid: Math.floor(Date.now() / 1000),
id: Date.now(),
attempts: 0,
delay: null,
maxExceptions: null,
displayName: 'App\\Jobs\\TestJob',
};
RedisClient.connect();
const appName = 'laravel';
const prefix = '_database';
const redisDatabase = 'default';
await RedisClient.rPush(`${appName}${prefix}:queues:${redisDatabase}`, [JSON.stringify(data)]);
RedisClient.disconnect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment