3

So I have MyJob.perform_in(60, @user), Which will perform my job in 60 seconds.

I want to cancel this Job if this line of code is ran again replacing it in the queue.

I have had no luck researching.

Gil F.
  • 31
  • 5

2 Answers2

0

To get the stats related to SuckerPunch jobs

[14] pry(main)> SuckerPunch::Queue.stats
{
    "CreateVVLinkJob" => {
        "workers" => {
            "total" => 1,
             "busy" => 0,
             "idle" => 1
        },
           "jobs" => {
            "processed" => 1,
               "failed" => 0,
             "enqueued" => 0
        }
    }
}

And To Clear the previous jobs

[24] pry(main)> SuckerPunch::Queue.clear
[
    [0] #<SuckerPunch::Queue:0x0000000b150da0 @__lock__=#<Mutex:0x0000000b150d50>, @__condition__=#<Thread::ConditionVariable:0x0000000b150d28>, @running=false, @name="CreateVVLinkJob", @pool=#<Concurrent::ThreadPoolExecutor:0x0000000b146ad0 @__lock__=#<Mutex:0x0000000b1469e0>, @__condition__=#<Thread::ConditionVariable:0x0000000b1469b8>, @min_length=2, @max_length=2, @idletime=60, @max_queue=0, @fallback_policy=:abort, @auto_terminate=false, @pool=[], @ready=[], @queue=[], @scheduled_task_count=1, @completed_task_count=1, @largest_length=1, @ruby_pid=22314, @gc_interval=30, @next_gc_time=25973.834404648, @StopEvent=#<Concurrent::Event:0x0000000b1468c8 @__lock__=#<Mutex:0x0000000b146878>, @__condition__=#<Thread::ConditionVariable:0x0000000b146850>, @set=true, @iteration=0>, @StoppedEvent=#<Concurrent::Event:0x0000000b1467d8 @__lock__=#<Mutex:0x0000000b146788>, @__condition__=#<Thread::ConditionVariable:0x0000000b146760>, @set=true, @iteration=0>>>
]

Hope this is useful !

ashishmohite
  • 1,120
  • 6
  • 14
0

There is no built-in method inside of the SuckerPunch framework, that I can see from the source code, of canceling a single queued up job or a job that is currently executing. It appears that clearing the job queue is an all or nothing function.

That said, it should be a trivial matter to add an extension method that queries the underlying ConcurrentTask framework and matches up your new job with an already queued job based on the value of the @user parameter.

Justin
  • 490
  • 1
  • 3
  • 11