I have a node app with a queue for processing jobs in the background. I have a file that exports a function which when run, creates a job in my queue. In that file, I also have the handler for this type of job. It looks like this:
const actuallyDoStuff = async (...) => { // code that takes time }; queue.process('do_stuff', async (job, done) => { try { await actuallyDoTheStuff(job.data); done(); } catch (err) { done(err); } }); const doStuff = async () => { const job = queue.create('do_stuff', { ... }); job.save(); }; module.exports = doStuff;
The thing is, they could be called the same if the other didn’t exist. What I’m wondering is if you guys had some good naming practices for cases like this one. Some of the options I considered:
- Adding a prefix to the function that actually does the work, like
doDoStuff
- Adding a suffix to the other function to specify that it’s creating a background job, like
doStuffBG
But I don’t really like those options. What are your good practices for cases like this one?