Automattic / Automattic/kue

How to remove or set TTL in a .process() method

Open
#1,149 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
9.4k
Forks
858
PR merge metrics
No merged PRs in 30d

Description

Can you set the job.TTL in once inside a .process() method call? I have take over this project built on 0.8.x and I the developer did not seem to create an actual "job" via "queue.create()".

The entire code is filled with nothing but .process calls. The app works and this is the code so not sure how to set a ttl on the job if he isn't using queue.create()???? It appears initMe is called in each .process call so can I set the ttl in the initMe() method?

`jobs.process('send_callback', 10, function(job, done){
var id = null;
var type = null;
var key = null;

function initMe(){
logMe("Got the following from payload: " + JSON.stringify(job));
id = job.data.id;
logMe("id: " + id);
type = job.data.type;
logMe("type: " + type);
key = job.data.key;
logMe("key: " + key);

sendCallback();
}

function displayTime() {
var str = "";

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()

if (minutes < 10) {
minutes = "0" + minutes
}
if (seconds < 10) {
seconds = "0" + seconds
}
str += hours + ":" + minutes + ":" + seconds;
return str;
}

function logMe(str){
console.log(displayTime() + " : " + str);
job.log(displayTime() + " : " + str);
}

function sendCallback(){
params = {
key: key,
type: type,
id: id
};
var post_data = querystring.stringify(params);
var post_options = {
hostname: DOMAIN,
port: 443,
path: "/v1/send_callback",
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
};
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
done();
});
});
post_req.write(post_data);
post_req.end();
}

initMe();
});`

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names only the jobs.process callback, queue.create(), and initMe(); it names no files or tests. Start by tracing the process callback's job object and comparing it with jobs created through queue.create(). Done means a clear, documented answer explains where TTL can be set for this usage, or confirms that the API cannot do so.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.