How to save stuff to .doit.db files from within tasks for use in later doit executions?

34 views
Skip to first unread message

Johan Kjölhede

unread,
Dec 22, 2014, 4:53:22 PM12/22/14
to pytho...@googlegroups.com
I'd like to store some values in the doit db files.

More specifically I have my own uptodate functions that need to compare with values from previous executions, and I thought the db files would be the best place to store previous results.. But I don't know how to do it from within my tasks :).

Is there an api for doing this?
How would I access that same information during a later execution?



Tom Varga

unread,
Dec 22, 2014, 5:11:02 PM12/22/14
to pytho...@googlegroups.com
I'm not an expert on this yet, but I did just implement something like what you're looking for.
You do have to implement your own uptodate fuction.
My solution is based on the timeout example from the documentation.
In my case I wanted to store timestamps of some optional files so I updated the save_now function like this:

    def __call__(self, task, values):
        def save_now():
            save = {'success-time': time.time()}
            if self.optionalFiles:
                optional = {}
                for fileName in self.optionalFiles:
                    if os.path.exists(fileName):
                        optional[fileName] = os.path.getmtime(fileName)
                    else:
                        optional[fileName] = None
                save['optional-times'] = optional
            return save

Later on, I then get the past timestamps using:

            optional = values.get('optional-times', None)

Hope that helps.
-Tom

--
You received this message because you are subscribed to the Google Groups "python-doit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-doit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Kjölhede

unread,
Dec 22, 2014, 5:30:28 PM12/22/14
to pytho...@googlegroups.com
Ok, so that actually saves it to the .doit.db files? I thought the example in the documentation just saved so I could read it later during the same process execution? 

Tom Varga

unread,
Dec 22, 2014, 5:54:31 PM12/22/14
to pytho...@googlegroups.com
My impression is that the save_now function is called after completion of the task and the return values are stored in the db file.
Then upon the next invocation of doit, the rest of the __call__ function can access those values from the values var with lines like:

        last_success = values.get('success-time', None)

-Tom

Johan Kjölhede

unread,
Dec 22, 2014, 6:31:31 PM12/22/14
to pytho...@googlegroups.com
Wonderful :). 
Thanks. 
Reply all
Reply to author
Forward
0 new messages