Comments (1)
If you apply a lock on the row before removing it, would that prevent solid_queue from working on it?
No, as the polling and claiming applies to ready_executions
and claimed_executions
records, not jobs.
About what would happen, it'd depend on when it gets deleted and whether you have this foreign key in your DB:
add_foreign_key :solid_queue_claimed_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
which is added by the default migration.
Here's the relevant code that handles job processing, part of ClaimedExecution:
def perform
result = execute
if result.success?
finished
else
failed_with(result.error)
end
ensure
job.unblock_next_blocked_job
end
private
def execute
ActiveJob::Base.execute(job.arguments)
Result.new(true, nil)
rescue Exception => e
Result.new(false, e)
end
def finished
transaction do
job.finished!
destroy!
end
end
def failed_with(error)
transaction do
job.failed_with(error)
destroy!
end
end
If the deletion is committed before the job
is loaded as part of
ActiveJob::Base.execute(job.arguments)
it won't get to run as job.arguments
will raise an exception due to job
being nil
. That exception will be captured and returned as a result per:
rescue Exception => e
Result.new(false, e)
end
However, another exception will be raised when calling failed_with
because job.failed_with
will fail due to job
being nil
. The ensure
block will run:
job.unblock_next_blocked_job
but it'll also fail because job
is nil
, and that error will get reported via on_thread_error
(through handle_thread_error
) if you have that configured.
The claimed execution would have been deleted with the job via the foreign key if you have that defined. If not, the claimed execution will be left behind and will be cleared up when the process that owned it is terminated.
If the deletion is committed after the job
is loaded in claimed_execution
but before it finishes running, the job will run and finish (ActiveJob::Base.execute(job.arguments)
). Then, we'll try to run:
def finished
transaction do
job.finished!
destroy!
end
But the two queries from job.finished!
and destroy!
; that would be something like:
UPDATE `solid_queue_jobs` SET `solid_queue_jobs`.`updated_at` = '...', `solid_queue_jobs`.`finished_at` = '...' WHERE `solid_queue_jobs`.`id` =..
DELETE FROM `solid_queue_claimed_executions` WHERE `solid_queue_claimed_executions`.`id` = ..
won't do anything because the job and the claimed execution would be gone from the database (the claimed execution would have been deleted with the job via the foreign key). If you didn't have the foreign key, then the claimed execution will get deleted there.
Then all will finish just fine, and it'd be similar to if the job had finished fine, and then it'd been deleted after being performed.
If the deletion is committed after the job
is loaded in claimed_execution
and after it finishes running, everything will be run normally. Your deletion will have to wait until the job is marked as finished or failed, as that'd take a lock on the job, and then it'll be deleted.
from solid_queue.
Related Issues (20)
- recurring task argument not successfully passing all ActiveJob supported types HOT 5
- Worker Configuration for Specific Queues in SolidQueue
- Dynamic scheduled tasks HOT 5
- Does SolidQueue work with Pgbouncer in transaction mode? HOT 3
- Best practices for looping Jobs?
- Job claiming erratic in Mac development HOT 3
- See ActiveSupport error after upgrading to 0.3.0: undefined local variable or method `__callbacks' for class ActiveSupport::CurrentAttributes HOT 5
- Instrumentation improvements HOT 4
- how can we ensure each job is consumed at least once? HOT 2
- undefined method `queue_adapter_name' for nil HOT 3
- silence_polling not working HOT 16
- Job fails when turbo_rails sends an empty string in the argument list HOT 12
- Workers eventually stop working HOT 18
- Occasional crash on MacOS in Development mode HOT 2
- Missing foreign keys according to `immigrant` HOT 2
- Generalize `silence_polling` to `silence_queries` HOT 1
- Default value for `enqueue_after_transaction_commit` HOT 3
- Job worker randomly restarts? HOT 4
- Database connection error in Solid Queue, but not Rails app HOT 22
- A way to schedule many instances of a recurring task with different args HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid_queue.