Module: Postburner::Commands

Extended by:
ActiveSupport::Concern
Included in:
Job
Defined in:
app/concerns/postburner/commands.rb

Overview

Concern providing Beanstalkd command methods for Postburner jobs.

Provides methods for interacting with Beanstalkd queue operations such as deleting, kicking, and extending TTR. All methods handle connection retries and gracefully handle missing bkid (e.g., in test mode).

Examples:

Basic Beanstalkd operations

class MyJob < Postburner::Job
  def perform(args)
    # ... work ...
    extend!  # Extend TTR during long operation
  end
end

job.delete!  # Remove from Beanstalkd
job.kick!    # Retry buried job

Instance Method Summary collapse

Instance Method Details

#delete!void

Note:

Does nothing if job has no bkid (e.g., in test mode)

Note:

Does not modify ActiveRecord model - only affects Beanstalkd

This method returns an undefined value.

Deletes the job from the Beanstalkd queue.

This is a Beanstalkd operation that removes the job from the queue but does NOT destroy the ActiveRecord model. Use #destroy or #remove! to also update the database record.

Automatically retries with fresh connection if Beanstalkd connection is stale. Called automatically by before_destroy callback when using #destroy.

Examples:

job.delete!  # Removes from Beanstalkd queue only
job.reload   # Job still exists in database

Raises:

  • (Beaneater::NotConnected)

    if Beanstalkd connection fails after retry

See Also:



107
108
109
110
111
112
113
114
# File 'app/concerns/postburner/commands.rb', line 107

def delete!
  return unless self.bk
  begin
    self.bk.delete
  rescue Beaneater::NotConnected => e
    self.bk!.delete
  end
end

#extend!void

Note:

Does nothing if job has no bkid (e.g., in test mode)

This method returns an undefined value.

Extends the job’s time-to-run (TTR) in Beanstalkd.

Calls touch on the Beanstalkd job, extending the TTR by the original TTR value. Use this during long-running operations to prevent the job from timing out.

Examples:

Process large file line by line

def perform(args)
  file = File.find(args['file_id'])
  file.each_line do |line|
    # ... process line ...
    extend!  # Extend TTR to prevent timeout
  end
end

See Also:

  • #bk


74
75
76
77
78
79
80
81
# File 'app/concerns/postburner/commands.rb', line 74

def extend!
  return unless self.bk
  begin
    self.bk.touch
  rescue Beaneater::NotConnected => e
    self.bk!.touch
  end
end

#kick!void

Note:

Does nothing if job has no bkid (e.g., in test mode)

Note:

Only works on buried jobs - see Beanstalkd documentation

This method returns an undefined value.

Kicks a buried job back into the ready queue in Beanstalkd.

This is a Beanstalkd operation used to retry jobs that were buried due to repeated failures or explicit burial. Does not modify the ActiveRecord model.

Automatically retries with fresh connection if Beanstalkd connection is stale.

Examples:

job.kick!  # Moves buried job back to ready queue

Raises:

  • (Beaneater::NotConnected)

    if Beanstalkd connection fails after retry

See Also:



44
45
46
47
48
49
50
51
# File 'app/concerns/postburner/commands.rb', line 44

def kick!
  return unless self.bk
  begin
    self.bk.kick
  rescue Beaneater::NotConnected => e
    self.bk!.kick
  end
end

#remove!void

Note:

Idempotent - does nothing if already removed

Note:

Does not destroy ActiveRecord model - only soft deletes

This method returns an undefined value.

Soft-deletes the job by removing from Beanstalkd and setting removed_at timestamp.

Unlike #destroy, this preserves the job record in the database for audit trails while removing it from the Beanstalkd queue and marking it as removed.

Examples:

job.remove!
job.removed_at  # => 2025-10-31 12:34:56 UTC
job.persisted?  # => true (still in database)

Raises:

  • (Beaneater::NotConnected)

    if Beanstalkd connection fails

See Also:



136
137
138
139
140
# File 'app/concerns/postburner/commands.rb', line 136

def remove!
  return if self.removed_at
  self.delete!
  self.update_column(:removed_at, Time.current)
end