Tasks.js
[gitlive] / Tasks.js
1
2 XObject = imports.XObject.XObject;
3 XMLHttpRequest = imports.XMLHttpRequest.XMLHttpRequest;
4 Netrc = imports.Netrc.Netrc;
5 Date = imports.Date.Date;
6 /**
7  *
8  * Tasks
9  *
10  *  Flow
11  *
12  *    Commit
13  *      => Tasks.notify(commit)
14  *
15  *
16  *
17  *
18  */
19
20 Tasks = {
21     
22     curTask : false,
23     commitRepo : false, // the DB version of repo info..
24     lastCommit : false,
25     
26     notify : function(commit)
27     {
28         if (this.inQuery && this.inQuery > (new Date())) {
29             // ignore the notification.. we are currently checking what the current
30             // status is.
31             
32             // we need to handle a WTF situation where something below failed... so
33             
34             return; 
35         }
36         this.inQuery = (new Date()).add(Date.MINUTE, 5);
37         this.lastCommit = commit;
38         this.fetchTask();
39         
40         
41     },
42     fetchTask: function()
43     {
44         // have we got the status in the last 15 mins..
45         // we should not need to get it again... - it's probably not changed.
46         if (this.curTask && !this.curTask.hasExpired()) {
47             this.fetchRepo();
48         }
49         _this = this;
50         // do the request to get the task..
51         var r = new XMLHttpRequest({
52             onreadystatechange : function() {
53                 print("Got result.");
54                 if (this.status != 4) {
55                     return;
56                 }
57                 
58                   
59                 var res = JSON.parse(this.responseText);
60                 
61                 //print(JSON.stringify(res,null,4))
62                 //print([ res.success , res.data.length ]);
63                 _this.curTask = (res.success && res.data.length) ? (new Task(res.data[0])) : false;
64                 print(JSON.stringify(_this.curTask,null,4));
65                 _this.fetchRepo();
66             }
67             
68         });
69         var netrc  = Netrc.forHost('git.roojs.com');
70         
71         r.open('GET',
72                "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
73                ,true, netrc.login, netrc.password  );
74         //print("SEding request");        
75         r.send();
76         
77     },
78     
79     verifyCommit : function()
80     {
81         // using curTask + lastCommit decide what to do.
82         
83         
84         
85         
86         
87         this.inQuery = 0;
88         
89     },
90     
91     fetchRepo: function(repo)
92     {
93          _this = this;
94         var r = new XMLHttpRequest({
95             onreadystatechange : function() {
96                 print("Got result.");
97                 if (this.status != 4) {
98                     return;
99                 }
100                 
101                   
102                 var res = JSON.parse(this.responseText);
103                 
104                 //print(JSON.stringify(res,null,4))
105                 //print([ res.success , res.data.length ]);
106                 _this.commitRepo = (res.success && res.data.length) ? currRepores.data[0] : false;
107                 print(JSON.stringify(_this.commit))
108                 _this.verifyCommit();
109             }
110             
111         });
112         var netrc  = Netrc.forHost('git.roojs.com');
113         
114         r.open('GET',
115                "http://roojs.com/admin.php/Roo/mtrack_repo?name=" + repo.name
116                ,true, netrc.login, netrc.password  );
117         //print("SEding request");        
118         r.send();
119         
120         
121     }
122     
123     
124     
125     
126     
127     
128 };
129
130
131
132
133
134 Task = XObject.define(
135     function(cfg) {
136         // cal parent?
137         if (typeof(cfg) != 'object') {
138             print("CFG not oboject?");
139             return;
140         } 
141         XObject.extend(this,cfg);
142  
143         // fix up the values.
144         this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
145       // print("ACT DT: " + this.action_dt);
146         
147     },
148     Object,
149     {
150         /**
151          * This is similar to the cash_invoice_entry data..
152          * 
153          */
154         action_dt: '', //"2012-11-23 11:00:00"
155         description: '', //"QA on new site"
156         qtyvalue: 0, //"2.25"
157         
158         hasExpired : function()
159         {
160             
161             var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
162             return (new Date()) > exp;  
163             
164         }
165     }
166 );
167
168
169
170
171
172
173
174
175
176
177 //-------------- testing
178 Gtk = imports.gi.Gtk;
179 Gtk.init(Seed.argv);
180 Tasks.notify(1);
181 Gtk.main();