Skip to content

Advanced Running

Robin Miller edited this page Sep 18, 2022 · 4 revisions

Similar to running serially in test suites, you can also chain threaded or daemonized!.

Threaded

Threaded working will spawn a worker thread per queue.

Use threaded working for task queues that should only run while the main application is running. This includes the usual caveats around multithreading, so proceed with caution.

# work tasks until the application exits
scheduler.work.threaded

# work tasks for 5 seconds
scheduler.work.threaded(timeout: 5)

# only work tasks on greeting and reminder queues
scheduler.work(:greeting, :reminders).threaded

Daemonized

Daemonized working consumes the current process and then proceeds with threaded working in the new daemon.

Use daemonized working for production environments, especially in conjunction with daemon monitors like Monit.

Process ID files are a single-line file that saves the daemon's process ID number. It's saved to the directory given by :pid_dir. The default location is in /tmp.

# work tasks forever as a headless daemon process.
scheduler.work.daemonized!

# you can specify the directory to save the procrastinator.pid file 
scheduler.work.daemonized!(pid_path: '/var/run')

# using a path with .pid extension will name the process. This will become 'my-app'
scheduler.work.daemonized!(pid_path: '/var/run/my-app.pid')

# only work tasks in the 'greeting' and 'reminder' queues
scheduler.work(:greeting, :reminders).daemonized!

Procrastinator endeavours to be thread-safe and support concurrency, but this flexibility allows for many possible combinations. Expected use is a single process with one thread per queue. More complex use is possible but Procrastinator can't guarantee concurrency in your Task Store.

Clone this wiki locally