NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

Background workers and job queues on Schokr

Run background workers on Schokr: in-process queues, a separate worker server, and external Redis or database-backed queues like BullMQ and Celery.

Updated · 1 min read

Schokr does not include Redis or a managed queue, but you can still run background jobs. For small apps, process jobs inside your app or use a SQLite-backed queue. For heavier work, run a separate worker server and connect it to an external Redis or database provider.

Option 1: in-process jobs

For light work (sending an email, resizing an image), do it in the same process after responding:

app.post('/signup', async (req, res) => {
  res.status(202).json({ ok: true })
  setImmediate(() => sendWelcomeEmail(req.body.email).catch(console.error))
})

Downside: if the server restarts, queued work in memory is lost.

Option 2: a persistent queue in SQLite

Store jobs in a table and poll it. Jobs survive restarts and you need nothing external:

import sqlite3, time

db = sqlite3.connect("jobs.db")
db.execute("create table if not exists jobs (id integer primary key, payload text, done integer default 0)")

while True:
    row = db.execute("select id, payload from jobs where done = 0 order by id limit 1").fetchone()
    if row:
        process(row[1])
        db.execute("update jobs set done = 1 where id = ?", (row[0],))
        db.commit()
    else:
        time.sleep(2)

Run this loop in a background thread or a separate worker process. See SQLite in production for concurrency tips.

Option 3: a separate worker server

You can split work across your team's servers (up to 4 on the free package). Create a second Node.js, Bun or Python server whose startup runs only the worker. Note that two servers do not share files, so they need a shared external store to pass jobs between them.

Option 4: external Redis with BullMQ or Celery

If you use a hosted Redis provider, popular libraries work normally:

RuntimeLibraryNeeds
Node.js, BunBullMQRedis
PythonCeleryRedis or RabbitMQ
PythonRQRedis

BullMQ example:

const { Queue, Worker } = require('bullmq')
const connection = { url: process.env.REDIS_URL }

const queue = new Queue('emails', { connection })
await queue.add('welcome', { to: 'user@example.com' })

new Worker('emails', async (job) => {
  await sendEmail(job.data.to)
}, { connection })

Keep REDIS_URL in a .env file (see environment variables). Choose a Redis provider region close to your Schokr server's location to keep latency low.

Tips

  • Make jobs idempotent so retrying one twice does no harm.
  • Log job failures clearly; they appear in your server's console. See reading logs.
  • For jobs that run on a timetable rather than on demand, see scheduled jobs.