collectiveidea / delayed_job_active_record

ActiveRecord backend integration for DelayedJob 3.0+
MIT License
346 stars 336 forks source link

Prevent attempts to write too long error messages #200

Closed severin closed 4 months ago

severin commented 2 years ago

Attempting to write unchecked error messages leads to exceptions with the mysql2 adapter (something like ActiveRecord::ValueTooLong: Mysql2::Error: Data too long for column 'last_error').

Assigning the error message and persisting the job (when rescheduling it) happens in the exception handler of the run method in the worker and is not "guarded" by further exception handers, so any exception raised in this code crashes the worker process. Therefore I think it is worth fixing this even though the fix is maybe a bit ugly...

If you have any other ideas on how to address the issue differently thenI'm all ears and willing to change this PR or contribute a different PR 🙂

severin commented 2 years ago

@albus522 pinging you since I see that you are the most active committer in this repo 😉 Any interest in merging this? Feel free to close the PR as irrelevant if you don't think it makes sense.

albus522 commented 2 years ago

Different database instances have different limits and I don't know that a general truncation is the correct approach here.

c960657 commented 3 days ago

The actual database limit can be retrieved using Delayed::Job.type_for_attribute(:last_error).limit. The limit is in bytes, not characters, so truncating should use e.g. truncate_bytes.