Commit c9a65fb63ff4ebe672253e93cad6ddd98bdf814d
1 parent
cf377ff8
Exists in
timestamp_plugins
Adding timestamp feature to plugins
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Simião Carvalho <simiaosimis@gmail.com>
Showing
2 changed files
with
36 additions
and
1 deletions
Show diff stats
colab/plugins/models.py
| ... | ... | @@ -3,8 +3,19 @@ from datetime import datetime |
| 3 | 3 | |
| 4 | 4 | class TimeStampPlugin(models.Model): |
| 5 | 5 | ''' |
| 6 | - Class used to store timestamp from plugins | |
| 6 | + Class used to store timestamps from plugins | |
| 7 | 7 | ''' |
| 8 | 8 | id = models.IntegerField(primary_key= True) |
| 9 | 9 | name = models.CharField(max_length=255,unique=True,null=False) |
| 10 | 10 | timestamp = models.DateTimeField(default=datetime.min,blank=True) |
| 11 | + | |
| 12 | + @classmethod | |
| 13 | + def update_timestamp(cls, class_name): | |
| 14 | + instance = TimeStampPlugin.objects.filter(name=class_name)[0] | |
| 15 | + instance.timestamp = datetime.now() | |
| 16 | + instance.save() | |
| 17 | + | |
| 18 | + @classmethod | |
| 19 | + def get_last_updated(cls, class_name): | |
| 20 | + instance = TimeStampPlugin.objects.get_or_create(name=class_name)[0] | |
| 21 | + return instance.timestamp | ... | ... |
docs/source/plugindev.rst
| ... | ... | @@ -79,3 +79,27 @@ signals structure, some steps are required: |
| 79 | 79 | |
| 80 | 80 | .. code-block:: shell |
| 81 | 81 | celery -A colab worker --loglevel=debug |
| 82 | + | |
| 83 | +Storing TimeStamp | |
| 84 | +--------------- | |
| 85 | +TimeStamp is a parameter to control the last time a model was updated, you should use it | |
| 86 | +when you want the data updated after a given time. To do that the colab's model (colab.plugins.models) have a | |
| 87 | +TimeStampPlugin class, used to store all last updates from timestamp from all plugins. | |
| 88 | + | |
| 89 | +Class Methods: | |
| 90 | + update_timestamp(cls,class_name): allow store a current datetime. | |
| 91 | + | |
| 92 | + get_last_updated_timestamp(cls,class_name): allow get a datetime with last timestamp stored from class_name. | |
| 93 | + | |
| 94 | +Example Usage: | |
| 95 | + | |
| 96 | +.. code-block:: python | |
| 97 | + from colab.plugins.models import TimeStapPlugin | |
| 98 | + | |
| 99 | + class TestPlugin(): | |
| 100 | + | |
| 101 | + def update_timestamp(self): | |
| 102 | + TimeStapPlugin.update_timestamp('TestPlugin') | |
| 103 | + | |
| 104 | + def get_last_updated_timestamp(self): | |
| 105 | + return TimeStapPlugin.get_last_updated_timestamp('TestPlugin') | ... | ... |