DataMapper backend causing timestamp issues with background job processing

I’m running into a weird issue when trying to use DataMapper with a background job processing library. My current gem setup includes:

background_job 2.1.0.pre2
background_job_data_mapper 1.0.0.rc

I can set up the backend and add jobs to the queue just fine:

BackgroundJob::Worker.backend = :data_mapper
BackgroundJob::Worker.backend.auto_upgrade!

Jobs get stored in the database without any problems. But when I try to start a worker process using a rake task, it boots up okay but then crashes when trying to fetch jobs from the queue. The error message I get is:

rake aborted!
expected a time or date, got Mon Mar 15 14:22:33 -0500 2011

The stack trace shows the error is happening in the find_available method when it tries to do some time calculations. It looks like there’s a format mismatch between what DataMapper is returning and what the job processing system expects.

Has anyone run into this before? Is there a workaround or maybe a different approach to get DataMapper working with background job processing? I’m wondering if there’s a gem version compatibility issue or if I need to configure something differently.

I hit this exact problem migrating a legacy app. DataMapper’s timezone handling doesn’t play nice with background job processors. DataMapper returns timezone-aware strings but your job processor wants clean DateTime objects. Two fixes worked for me: add DataMapper.setup(:default, your_database_url + '?timezone=utc') to force UTC handling, or override find_available in your job model and use DateTime.parse() before doing time calculations. Fixed my production crashes without upgrading gems.

Classic datetime serialization issue. Add DataMapper::Property::DateTime explicitly to your job model if u haven’t. Also, those gem versions are ancient - pre-release versions have buggy timestamp handling.

Hmm, that’s interesting - what database are you using, SQLite or PostgreSQL? I’ve run into similar timestamp parsing issues where the DB returns strings instead of datetime objects. Can you share your DataMapper model for the job table?