kerinin schrieb:
> I'm trying to get a very basic scheduler set up. All I really need is
> to execute a function once a day which pulls blog posts from an RSS
> feed and adds them to the TG database.
>
> I've tried using TGScheduler and it's been a spectacular failure.
> There doesn't seem to be any documentation, and what I've managed to
> glean from the source notes isn't enough to get it to work. In short,
> it's been a waste of my time.
>
> So instead I've been using repeating timers from the threading module.
> This seems to work OK - my code is pulling the RSS feed and parsing it
> correctly, but for some reason none of my database changes are
> sticking. I'm triggering the timer from in one of my controllers, and
> it starts working the first time the controller is imported. Is there
> a better place to call random functions from? Is there some reason
> why using DBSession outside of a page request doesn't ever commit my
> data?
You don't show code, but I guess it's because you don't use
transactions. This is implicitly done for you within actions, but if you
run in threads, you need to do something along these lines:
import transaction
def my_scheduler_callback():
try:
transaction.begin()
... # code with DBSession-usage.
except:
transaction.rollback() # or abort? not 100% sure here
else:
transaction.commit()
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---