Ahenk/opt/ahenk/base/model/task.py

69 lines
1.8 KiB
Python
Raw Normal View History

2016-03-02 11:33:48 +02:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
2016-03-21 12:02:15 +02:00
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
2016-03-07 17:13:03 +02:00
import json
2016-03-02 11:33:48 +02:00
2016-08-24 18:00:01 +03:00
from base.model.plugin import Plugin
2016-03-02 11:33:48 +02:00
class Task(object):
"""docstring for Task"""
def __init__(self, message):
2016-04-05 17:57:35 +03:00
#TODO message must be json !!! otherwise we can not use task json methods!
#Remove if condition and change message param to json task type.
if message:
self.task = message['task']
2016-03-02 11:33:48 +02:00
2016-03-07 17:13:03 +02:00
@property
2016-03-21 12:02:15 +02:00
def id(self):
return self.task['id']
2016-03-14 10:55:28 +02:00
@property
2016-03-21 12:02:15 +02:00
def create_date(self):
2016-03-24 17:55:23 +02:00
return self.task['createDate']
2016-03-21 12:02:15 +02:00
@property
def modify_date(self):
2016-03-24 17:55:23 +02:00
return self.task['modifyDate']
2016-03-21 12:02:15 +02:00
@property
def command_cls_id(self):
2016-04-11 19:26:49 +03:00
return json.loads(str(self.task))['commandClsId']
2016-03-21 12:02:15 +02:00
@property
def parameter_map(self):
2016-03-24 17:55:23 +02:00
return self.task['parameterMap']
2016-03-21 12:02:15 +02:00
@property
def deleted(self):
return self.task['deleted']
@property
def plugin(self):
2016-04-11 19:26:49 +03:00
return Plugin(json.loads(str(self.task)))
2016-03-21 12:02:15 +02:00
2016-04-05 15:23:20 +03:00
@property
def cron_str(self):
return '1 * * * *' #TODO update when task cron field added.
2016-03-21 12:02:15 +02:00
def to_string(self):
return str(self.task)
def to_json(self):
2016-04-05 15:23:20 +03:00
return json.dumps(self.task)
def from_json(self,json_value):
self.task = json.load(json_value)
2016-03-29 11:52:18 +03:00
@property
def obj_name(self):
return "TASK"
2016-04-05 15:23:20 +03:00
def cols(self):
return ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin']
def values(self):
return [str(self.id), str(self.create_date), str(self.modify_date), str(self.command_cls_id), str(self.parameter_map), str(self.deleted), self.plugin.to_string()]