I don't seem to be be able to run a background task.
I invoke the background process as so...
$handle = background_process_start('my_background_probe');
I have a function in my module defined
function my_background_probe()
{
debug('my_background_probe');
}
In the config/overview for background process I can see my created processes...
But I don't see "my_background_probe" in the logs.
Any ideas?
Is there a complete example somewhere?
Can you call debug() from inside a background process?
I am running with Drupal 7/Microsoft Web Platform PHP IIS7.5 and SQL 2008.
Thanks.
Comments
Comment #1
gielfeldt commentedHi
You can call debug() from within a background process. It will only log to watchdog of course, and not the screen. The above code works for me. But if you say you can see your process in the config overview, i suspect the process is never started at all, as it should be removed again almost instantaneously when it finishes.
Are there any logs from Background Process in watchdog?
Also, did you configure background process in settings.php? If not, try to go to admin/config/system/background-process and click "Determine default service host" and let me know what it reports.
Comment #2
DrMiaow commentedThanks for the quick reply.
Testing it now under Aquia drupal. Getting the same behavior.
It reports
Which is what it also said when the module was first installed.
I see no log messages from the background process in http://localhost:8082/admin/reports/
I see a log message from before and after my call to
background_process_start('my_background_probe');but I don't see any sign of thedebug('my_background_probe');in the logs.Comment #3
gielfeldt commentedStrange. If the default service host determination works, then the background_process_start() should work as well, as they use the same mechanism.
I'll have to think more about this to develop a theory.
Do you get any errors in your webserver logs? Do you see any requests to urls containing 'bgp:start' in your access logs?
Comment #4
DrMiaow commentedFound this. Any help?
[Mon Mar 19 16:50:12 2012] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map POST /bgp%3Astart/10b1047ea5291c445891e1177ec8a325/444a288fa091e359ca3d8294f1957916 HTTP/1.0 to file, referer: http://localhost:8082/admin/content/tracks/add?render=overlay[Mon Mar 19 16:52:39 2012] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map POST /bgp%3Astart/719e72ce6130b8e8209e514c4144e1df/1b7707f3d36732cb9b1d2df64caef525 HTTP/1.0 to file, referer: http://localhost:8082/admin/content/tracks/add?render=overlay
[Mon Mar 19 17:01:36 2012] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map POST /bgp%3Astart/16954c4566aada54848cb799097407c1/97354a070dfcec88ba756c89fe7f097e HTTP/1.0 to file, referer: http://localhost:8082/admin/content/tracks/add
[Mon Mar 19 17:22:03 2012] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map POST /bgp%3Astart/1102796a40155aa94b6d1a5431872124/6c35233666ace644604347c4da88305b HTTP/1.0 to file, referer: http://localhost:8082/admin/content/tracks/add?render=overlay
Comment #5
gielfeldt commentedahhh ... crap. Using colon in an URL is not to IIS friendly.
You might be able to configure your webserver to accept it though (via web.config): http://stackoverflow.com/questions/667429/using-a-colon-in-a-url-with-as...
I'll change the colon (if possible). I'll let you know when or if. Then you can try out the 7.x-dev version. I don't know when I'll get the time though, so let me know if it's possible to apply the IIS "fix".
Comment #6
gielfeldt commentedAlso if you're up for it, you can try to replace all 'bgp:' with e.g. 'bgp-' and post a patch to me.
Comment #7
DrMiaow commentedThat log is from Apache running under Windows using Acquia, but I get the same result.
After a rename and re-install of the module I get errors in debug log
Comment #8
gielfeldt commentedThat's odd. I'm not sure these errors are related though. Could try clearing cache, and then make sure the background process table is clear, and then run your code again?
Comment #9
DrMiaow commentedCleared cache.
http://localhost:8082/admin/config/system/background-process/overview shows nothing.
background_process table is empty.
Same result.
I started hacking around in the code.
Looks like some kind of caching issue/race condition with writing and reading the database. The incoming request to bgp-start fails to find the process in the table. (
background_process_get_processseems to fail find the process by it's handle value, despite it being in the database. )BUT!
If I repeat the request (cut and paste from logs) , then the process fires.
So it seems that timing is important... I have verified that
$handlewas identical in both calls.Logging in 'newest first' order
After I paste in the URL background_process_get_process: b1627fcd1822c530806918726866f205
The original attempt. background_process_get_process: b1627fcd1822c530806918726866f205
I added some logging to background_process_get_process to track when it was finding it...
Comment #10
gielfeldt commentedThe plot thickens ... Are you using INNODB with AUTOCOMMIT=0 and REPEATABLE_READ isolation level?
Comment #11
DrMiaow commentedLooks like autocommit = 1
Comment #12
gielfeldt commentedHmmm, weeeeeird. I'll be back...
Comment #13
gielfeldt commentedWould be possible for you to do a:
Just to check if it's the InnoDB transactions/isolation level that's the culprit.
Comment #14
DrMiaow commentedThat seemed to do the trick.
Comment #15
gielfeldt commentedInteresting. Do you know if you're inside a transaction (manually started or otherwise), when you launch the background process?
Btw, I'll fix the url-stuff soon and post here when I've committed to dev.
Comment #16
DrMiaow commentedThanks.
I am creating the background process in an implementation of hook_node_presave.
I don't know if Drupal calls that while in a transaction, but it is plausible. It would certainly explain what I am seeing.
Comment #17
gielfeldt commentedIt's very plausible. I see 2 solutions:
1.) change the engine for background_process table to e.g. MyISAM.
2.) use a different connection for the background_process table if inside a transaction.
Thoughts?
Comment #18
DrMiaow commented1) Wont work consistently. (MSSQL etc.).
2) Yes. That would work and not have too much of a side-effect (other than database load).
also
3) Defer the creation of the background process till we are out of scope of the transaction, like at the end of the request? reliability if there was an error between the declaring our intention to create the process and the and of the request where we add it to the database.
Comment #19
gielfeldt commentedI though about the deferring as well, but that's just going to give me more problems than benefits, I suspect.
I'll think I'll look into number 2) as you are right about 1). My question in #18 almost seemed rhetorical after reading it again :-)
Comment #20
gielfeldt commentedUse of different connection for background processes has been committed to dev.
The easiest way to make use of it, is to add the following to settings.php right after your $databases definition (php tags included for syntax highlighting only):
Comment #21
gielfeldt commented