Rails 5: delete an ActiveJob before it gets performed
up vote
0
down vote
favorite
I have an ActiveJob that changes a record's status field from "pending" to "live" X minutes after it's been created. It works well.
When the user edits the record within the X minutes, I need to push back that status change, viz. restart the clock. Presumably I'd do this by cancelling the ActiveJob and creating a new one. The Rails Guides for ActiveJob don't mention how this should be done.
I see that I can assign the ActiveJob to a variable like this:
j = ThingLiveJob.set(wait: 1.minute).perform_later(@thing)
and using byebug
immediately after this line (in the controller), I see that it outputs like this:
#<ThingLiveJob:0x000000134a5fc0 @arguments=[#<Thing id: 1095, body: "Whatever", user_id: 1, created_at: "2018-11-19 10:34:24", updated_at: "2018-11-19 10:34:24", status: "pending">], @job_id="aab28c66-f8b4-491e-9c7f-af6f27aa482e", @queue_name="default", @priority=nil, @executions=0, @scheduled_at=1542623724.674397, @provider_job_id="61c154d5-9c1b-45a1-8487-824a4412c53c">
However, at the console, neither of these (guesses) work:
j.destroy
j.delete
So how should I go about it?
ruby-on-rails rails-activejob
add a comment |
up vote
0
down vote
favorite
I have an ActiveJob that changes a record's status field from "pending" to "live" X minutes after it's been created. It works well.
When the user edits the record within the X minutes, I need to push back that status change, viz. restart the clock. Presumably I'd do this by cancelling the ActiveJob and creating a new one. The Rails Guides for ActiveJob don't mention how this should be done.
I see that I can assign the ActiveJob to a variable like this:
j = ThingLiveJob.set(wait: 1.minute).perform_later(@thing)
and using byebug
immediately after this line (in the controller), I see that it outputs like this:
#<ThingLiveJob:0x000000134a5fc0 @arguments=[#<Thing id: 1095, body: "Whatever", user_id: 1, created_at: "2018-11-19 10:34:24", updated_at: "2018-11-19 10:34:24", status: "pending">], @job_id="aab28c66-f8b4-491e-9c7f-af6f27aa482e", @queue_name="default", @priority=nil, @executions=0, @scheduled_at=1542623724.674397, @provider_job_id="61c154d5-9c1b-45a1-8487-824a4412c53c">
However, at the console, neither of these (guesses) work:
j.destroy
j.delete
So how should I go about it?
ruby-on-rails rails-activejob
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an ActiveJob that changes a record's status field from "pending" to "live" X minutes after it's been created. It works well.
When the user edits the record within the X minutes, I need to push back that status change, viz. restart the clock. Presumably I'd do this by cancelling the ActiveJob and creating a new one. The Rails Guides for ActiveJob don't mention how this should be done.
I see that I can assign the ActiveJob to a variable like this:
j = ThingLiveJob.set(wait: 1.minute).perform_later(@thing)
and using byebug
immediately after this line (in the controller), I see that it outputs like this:
#<ThingLiveJob:0x000000134a5fc0 @arguments=[#<Thing id: 1095, body: "Whatever", user_id: 1, created_at: "2018-11-19 10:34:24", updated_at: "2018-11-19 10:34:24", status: "pending">], @job_id="aab28c66-f8b4-491e-9c7f-af6f27aa482e", @queue_name="default", @priority=nil, @executions=0, @scheduled_at=1542623724.674397, @provider_job_id="61c154d5-9c1b-45a1-8487-824a4412c53c">
However, at the console, neither of these (guesses) work:
j.destroy
j.delete
So how should I go about it?
ruby-on-rails rails-activejob
I have an ActiveJob that changes a record's status field from "pending" to "live" X minutes after it's been created. It works well.
When the user edits the record within the X minutes, I need to push back that status change, viz. restart the clock. Presumably I'd do this by cancelling the ActiveJob and creating a new one. The Rails Guides for ActiveJob don't mention how this should be done.
I see that I can assign the ActiveJob to a variable like this:
j = ThingLiveJob.set(wait: 1.minute).perform_later(@thing)
and using byebug
immediately after this line (in the controller), I see that it outputs like this:
#<ThingLiveJob:0x000000134a5fc0 @arguments=[#<Thing id: 1095, body: "Whatever", user_id: 1, created_at: "2018-11-19 10:34:24", updated_at: "2018-11-19 10:34:24", status: "pending">], @job_id="aab28c66-f8b4-491e-9c7f-af6f27aa482e", @queue_name="default", @priority=nil, @executions=0, @scheduled_at=1542623724.674397, @provider_job_id="61c154d5-9c1b-45a1-8487-824a4412c53c">
However, at the console, neither of these (guesses) work:
j.destroy
j.delete
So how should I go about it?
ruby-on-rails rails-activejob
ruby-on-rails rails-activejob
asked 2 days ago


MSC
1,58621526
1,58621526
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
I've solved similar situations in my projects as follows... I queue the active_job after every record update or create, but I call it like:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id, @thing.updated_at)
Then in the activejob code...
def perform(thing_id, thing_updated_at)
thing = Thing.find(thing_id)
return if thing_updated_at != thing.updated_at
...
end
So essentially I let the active job run, but the active job checks that the thing object hasn't been updated since the current active job was queued.
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I've solved similar situations in my projects as follows... I queue the active_job after every record update or create, but I call it like:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id, @thing.updated_at)
Then in the activejob code...
def perform(thing_id, thing_updated_at)
thing = Thing.find(thing_id)
return if thing_updated_at != thing.updated_at
...
end
So essentially I let the active job run, but the active job checks that the thing object hasn't been updated since the current active job was queued.
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
add a comment |
up vote
2
down vote
accepted
I've solved similar situations in my projects as follows... I queue the active_job after every record update or create, but I call it like:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id, @thing.updated_at)
Then in the activejob code...
def perform(thing_id, thing_updated_at)
thing = Thing.find(thing_id)
return if thing_updated_at != thing.updated_at
...
end
So essentially I let the active job run, but the active job checks that the thing object hasn't been updated since the current active job was queued.
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I've solved similar situations in my projects as follows... I queue the active_job after every record update or create, but I call it like:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id, @thing.updated_at)
Then in the activejob code...
def perform(thing_id, thing_updated_at)
thing = Thing.find(thing_id)
return if thing_updated_at != thing.updated_at
...
end
So essentially I let the active job run, but the active job checks that the thing object hasn't been updated since the current active job was queued.
I've solved similar situations in my projects as follows... I queue the active_job after every record update or create, but I call it like:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id, @thing.updated_at)
Then in the activejob code...
def perform(thing_id, thing_updated_at)
thing = Thing.find(thing_id)
return if thing_updated_at != thing.updated_at
...
end
So essentially I let the active job run, but the active job checks that the thing object hasn't been updated since the current active job was queued.
answered 2 days ago
SteveTurczyn
25.6k42738
25.6k42738
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
add a comment |
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
Sounds good. I'll see whether anyone else has a better idea overnight and come back to you in the morning.
– MSC
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I'm doing same.
– Pavel Mikhailyuk
2 days ago
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I am getting "Unsupported argument type: Time". I need to read the docs again...
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
I needed to convert both parameters to strings to get this to work:
ThingLiveJob.set(wait: 1.minute).perform_later(@thing.id.to_s, @thing.updated_at.to_i.to_s)
– MSC
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373100%2frails-5-delete-an-activejob-before-it-gets-performed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown