const SqsObject = new AWS.SQS();
const { v4: uuid } = require('uuid');
const { serialize } = require('php-serialize')
const pushToQueue = (jobName, response) => {
return new Promise((resolve, reject) => {
class Job {
constructor(payload) {
this.job = null;
this.connection = null;
this.queue = null;
this.chainConnection = null;
this.chainQueue = null;
this.chainCatchCallbacks = null;
this.delay = null;
this.afterCommit = null;
this.middleware = [];
this.chained = [];
this.payload = payload;
}
}
const JobNameWithNamespace = `App\\Jobs\\${jobName}`;
const result = {
uuid: uuid(),
displayName: JobNameWithNamespace,
job: "Illuminate\\Queue\\CallQueuedHandler@call",
maxTries: null,
maxExceptions :null,
backoff :null,
timeout :null,
retryUntil :null,
data: {
commandName: JobNameWithNamespace,
command: serialize(new Job(response), {[JobNameWithNamespace]: Job})
},
};
const params = {
MessageBody: JSON.stringify(result),
QueueUrl: QUEUE_URL
};
SqsObject.sendMessage(params, function(err, data) {
if (err) {
reject(err)
} else {
resolve(data);
}
});
})
};
Dla potomnych, tak można puścić job do queue Laravelowego z poza PHP. Jakby ktoś znalazł lepszy sposób to priv