Last active
October 3, 2022 12:39
-
-
Save jeystaats/380505ed92235675c30cd82d0ceb0dea to your computer and use it in GitHub Desktop.
Add to Laravel Queue (Redis) from NodeJS [Laravel > 9 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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