Skip to content

Commit 9a56d7c

Browse files
update code
1 parent 2c42e1e commit 9a56d7c

8 files changed

Lines changed: 114 additions & 199 deletions

File tree

.vscode/PythonImportHelper-v2-Completion.json

Lines changed: 25 additions & 26 deletions
Large diffs are not rendered by default.

Disk0/task1.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,6 @@
2626
log_name = 'log_gcc.log' # Log file name
2727
#############################################################
2828

29-
"""
30-
31-
อธิบาย Mapfile ( ./data/LA00000.MAP )
32-
33-
ทุกครั้งที่จะเอาข้อมูลเข้า Database เราต้องทำการระบุชื่อฟิลด์ให้กับข้อมูลก่อน
34-
โดย ให้เข้าไประบุไว้ในไฟล์ .MAP
35-
36-
ใน mapfile จะมีส่วนที่กำหนดค่าอยู่ 3 ส่วน คือ HEADER, BODY, FOOTER
37-
38-
ยกตัวอย่าง (HEADER, BODY, FOOTER ใช้หลักการกำหนดแบบเดียวกัน) :
39-
#HEADER ( คือ ระบุว่าข้อมูลต่อจากนี้จะเป็นส่วนของ Column Header )
40-
#ENDHEADER ( คือ ระบุว่าให้หยุดอ่านข้อมูลของ Header )
41-
42-
"""
43-
44-
"""
45-
46-
* วิธีเรียกใช้งาน
47-
- python3 main.py -file_name=./data/LA00000.GCC -map_file_name=./data/LA00000.MAP -limit=100 -header=HT -body=DT -footer=FT
48-
49-
* อธิบาย Parameter :
50-
-file_name={value} ( ให้ใส่ Part ไฟล์ Source )
51-
-map_file_name={value} ( ให้ใส่ Part ไฟล์ Mapping )
52-
-limit={value} ( จำนวนข้อมูลต่อรอบการ Insert เช่น ใส่ 100 จะหมายถึง ให้อ่านข้อมูลครบ 100 rows ก่อนถึงค่อยทำการ Insert ลง Database )
53-
-header={value} ( ระบุชุดข้อมูลแบบ Header เช่น ใส่ HT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า HT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Header )
54-
-body={value} ( ระบุชุดข้อมูลแบบ Body เช่น ใส่ DT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า DT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Body )
55-
-footer={value} ( ระบุชุดข้อมูลแบบ Footer เช่น ใส่ FT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า FT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Footer )
56-
57-
* หมายเหตุ -header, -body, -footer ไม่ใส่ก็ได้ โปรแกรมจะ Default ค่าไว้ให้ HT, DT, FT ตามลำดับ
58-
59-
"""
60-
61-
"""
62-
ไฟล์ Log จะเก็บอยู่ที่ Folder logs
63-
"""
64-
6529
# Get Script path runing
6630
script_path = os.path.dirname(os.path.abspath(__file__))
6731
print('__name__', __name__)

Disk0/task2.py

Lines changed: 4 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import time
55
import sys
6-
import requests
6+
from client_api import clien_api_class
7+
78

89
# Note
910
# สิ่งแรกที่ task ควรจะได้มาพร้อม args คือ guid
@@ -25,42 +26,6 @@
2526
log_name = 'log_acc.log' # Log file name
2627
#############################################################
2728

28-
"""
29-
30-
อธิบาย Mapfile ( ./data/LA00000.MAP )
31-
32-
ทุกครั้งที่จะเอาข้อมูลเข้า Database เราต้องทำการระบุชื่อฟิลด์ให้กับข้อมูลก่อน
33-
โดย ให้เข้าไประบุไว้ในไฟล์ .MAP
34-
35-
ใน mapfile จะมีส่วนที่กำหนดค่าอยู่ 3 ส่วน คือ HEADER, BODY, FOOTER
36-
37-
ยกตัวอย่าง (HEADER, BODY, FOOTER ใช้หลักการกำหนดแบบเดียวกัน) :
38-
#HEADER ( คือ ระบุว่าข้อมูลต่อจากนี้จะเป็นส่วนของ Column Header )
39-
#ENDHEADER ( คือ ระบุว่าให้หยุดอ่านข้อมูลของ Header )
40-
41-
"""
42-
43-
"""
44-
45-
* วิธีเรียกใช้งาน
46-
- python3 main.py -file_name=./data/LA00000.GCC -map_file_name=./data/LA00000.MAP -limit=100 -header=HT -body=DT -footer=FT
47-
48-
* อธิบาย Parameter :
49-
-file_name={value} ( ให้ใส่ Part ไฟล์ Source )
50-
-map_file_name={value} ( ให้ใส่ Part ไฟล์ Mapping )
51-
-limit={value} ( จำนวนข้อมูลต่อรอบการ Insert เช่น ใส่ 100 จะหมายถึง ให้อ่านข้อมูลครบ 100 rows ก่อนถึงค่อยทำการ Insert ลง Database )
52-
-header={value} ( ระบุชุดข้อมูลแบบ Header เช่น ใส่ HT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า HT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Header )
53-
-body={value} ( ระบุชุดข้อมูลแบบ Body เช่น ใส่ DT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า DT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Body )
54-
-footer={value} ( ระบุชุดข้อมูลแบบ Footer เช่น ใส่ FT เมื่อโปรแกรมอ่านเจอขึ้นต้นว่า FT โปรแกรมจะเข้าใจว่าบรรทัดนั้นคือข้อมูล Footer )
55-
56-
* หมายเหตุ -header, -body, -footer ไม่ใส่ก็ได้ โปรแกรมจะ Default ค่าไว้ให้ HT, DT, FT ตามลำดับ
57-
58-
"""
59-
60-
"""
61-
ไฟล์ Log จะเก็บอยู่ที่ Folder logs
62-
"""
63-
6429
# Get Script path runing
6530
script_path = os.path.dirname(os.path.abspath(__file__))
6631
print('__name__', __name__)
@@ -86,65 +51,6 @@
8651

8752
#----------------------------------------------------------------------------#
8853

89-
# HELPER CLASS (ค่อยย้ายออกไปข้างนอก ตอนนี้ติดบัคอยู่ไม่รู้ว่าทำไม)
90-
class MyHelper:
91-
__api_url = 'http://localhost:8000'
92-
__guid = ""
93-
__pid = ""
94-
95-
def __init__(self, guid, pid):
96-
self.__guid = guid
97-
self.__pid = pid
98-
pass
99-
100-
# ตรวจสอบว่ามี guid นี้อยู่ใน database ไหม
101-
def api_get_task(self) :
102-
url = F"{self.__api_url}/api/helper/get_task"
103-
payload={'guid': self.__guid}
104-
response = requests.request("POST", url, headers={}, data=payload, files=[])
105-
if response.status_code == 200:
106-
return 1
107-
elif response.status_code == 404:
108-
return None
109-
pass
110-
111-
# Insert log ลง db
112-
def api_log_insert(self, message):
113-
try :
114-
url = F"{self.__api_url}/api/helper/insert_log"
115-
payload={'guid': self.__guid,'pid': self.__pid, 'message': message}
116-
requests.request("POST", url, headers={}, data=payload, files=[])
117-
except:
118-
print("Unexpected error:", sys.exc_info()[0])
119-
pass
120-
pass
121-
122-
def api_update_status(self, status):
123-
try :
124-
url = F"{self.__api_url}/api/helper/update_status"
125-
payload={
126-
'guid': self.__guid,
127-
'status': status
128-
}
129-
requests.request("POST", url, headers={}, data=payload, files=[])
130-
except:
131-
print("Unexpected error:", sys.exc_info()[0])
132-
pass
133-
pass
134-
135-
def api_update_pid(self):
136-
try :
137-
url = F"{self.__api_url}/api/helper/update_pid"
138-
payload={
139-
'guid': self.__guid,
140-
'pid': self.__pid
141-
}
142-
requests.request("POST", url, headers={}, data=payload, files=[])
143-
except:
144-
print("Unexpected error:", sys.exc_info()[0])
145-
pass
146-
pass
147-
#END OF HELPER CLASS
14854

14955
class ImportToMongo :
15056
__guid = ""
@@ -164,7 +70,6 @@ class ImportToMongo :
16470
__file_name = ""
16571
__map_file_name = ""
16672

167-
# __api_helpter = None
16873
__task_info = None
16974

17075
#TODO Move Constatn to New Class
@@ -197,12 +102,12 @@ def __init__(self):
197102
self.__pid = os.getpid()
198103

199104
# Init MyHelper สำหรับ Insert Logs
200-
self.__api_helpter = MyHelper(self.__guid, self.__pid)
105+
self.__api_helpter = clien_api_class(self.__guid, self.__pid)
201106
self.change_status(self.RUNNING) # UPDATE STATUS TO RUNNING
202107
self.update_pid()
203108
self.log(F'PID = {self.__pid}')
204109

205-
time.sleep(15)
110+
time.sleep(5)
206111

207112
# Check args
208113
if self.__guid == '':

django/Templates/create.index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
{% endblock %}
44

55
{% block content %}
6-
7-
86
<div ng-controller="createTaskCtrl" class="container" style="margin-top: 50px;">
97
<h3>New Task </h3>
108
<hr>

django/Templates/default.index.html

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
6565
<table style="width: 100%" class="table table-hover">
6666
<thead>
6767
<tr>
68-
<th>Id</th>
68+
<th></th>
6969
<th>Name</th>
7070
<th>File</th>
7171
<th>Args</th>
@@ -75,10 +75,16 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
7575
</thead>
7676
<tbody>
7777
<tr ng-repeat="i in task_list">
78-
<td>{$ i.id $}</td>
78+
<td>
79+
<img
80+
width="64px"
81+
src="https://www.flaticon.com/svg/vstatic/svg/2721/2721287.svg?token=exp=1612930192~hmac=a89affa656666a6c00875dfc42cac345"/>
82+
</td>
7983
<td>{$ i.task_name $}</td>
8084
<td>{$ i.file_name $}</td>
81-
<td>{$ i.args $}</td>
85+
<td>
86+
<textarea cols="40" rows="5" class="form-control" readonly>{$ i.args $}</textarea>
87+
</td>
8288
<td>{$ i.status $}</td>
8389
<td>
8490
<div ng-if="true || i.status == 'PENDING'">
@@ -99,9 +105,13 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
99105

100106
<button ng-click="func_log_task(i.guid)"
101107
class="btn btn-sm btn-default">LOG</button>
102-
{% comment %}
108+
103109
<button ng-click="func_edit_task(i.guid)"
104-
class="btn btn-warning">EDIT</button> {% endcomment %}
110+
class="btn btn-warning">EDIT</button>
111+
112+
<button ng-click="func_delete_task(i.guid)"
113+
class="btn btn-warning">DELETE</button>
114+
105115
</td>
106116
</tr>
107117
</tbody>
@@ -129,32 +139,31 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
129139
{% block script %}
130140
<script>
131141
app.controller("taskMonitorCtrl", function ($scope, $window) {
142+
$scope.task_list = []
143+
132144
$scope.url_api_show_all_task = "api/task/show";
133145
$scope.url_api_start_task = "api/task/start";
134146
$scope.url_api_reset_task = "api/task/reset";
135147
$scope.url_api_stop_task = "api/task/stop";
136148
$scope.url_api_delete_task = "api/task/delete";
137-
138-
$scope.task_list = []
149+
$scope.url_task_create = '/task/create';
150+
$scope.url_task_logs = '/task/logs';
139151

140152
$scope.init = function () {
141-
142153
$scope.func_show_all_task();
143-
setInterval(function(){
144-
$scope.func_show_all_task();
145-
}, 1000);
146154
};
147155
$scope.func_goto_create= function() {
148-
$window.location.href = '/task/create';
156+
$window.location.href = $scope.url_task_create;
149157
}
150158
$scope.func_show_all_task = function () {
151159
$.ajax({
152160
type: "POST",
153-
url: "./api/task/show",
161+
url: $scope.url_api_show_all_task,
154162
success: function (res) {
155163
$scope.$apply(function() {
156164
$scope.task_list = res;
157165
});
166+
ShowLoading(false);
158167
},
159168
error: function (jqXHR) {
160169
},
@@ -204,11 +213,7 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
204213
}
205214
$scope.func_log_task = function(guid) {
206215
ShowLoading(true);
207-
$window.location.href = '/task/logs?guid=' + guid;
208-
}
209-
$scope.func_edit_task = function(guid) {
210-
console.log(guid)
211-
//redirect to edit
216+
$window.location.href = $scope.url_task_logs + '?guid=' + guid;
212217
}
213218
$scope.func_reset_task = function(guid) {
214219
ShowLoading(true);
@@ -232,10 +237,50 @@ <h1 class="m-0 text-dark">Task Monitor</h1>
232237
},
233238
});
234239
}
235-
$scope.func_delete_tasl = function(guid) {
236-
240+
$scope.func_delete_task = function(guid) {
241+
var _data = {
242+
'guid' : guid,
243+
}
244+
Swal.fire({
245+
title: 'Are you sure?',
246+
text: "Would you like to delete this ?",
247+
icon: 'warning',
248+
showCancelButton: true,
249+
confirmButtonColor: '#3085d6',
250+
cancelButtonColor: '#d33',
251+
confirmButtonText: 'Yes, delete it!'
252+
}).then(function(result){
253+
if (result.isConfirmed) {
254+
$.ajax({
255+
type: "POST",
256+
url: $scope.url_api_delete_task,
257+
data: _data,
258+
success: function (res) {
259+
Swal.fire(
260+
'Deleted!',
261+
'Your file has been deleted.',
262+
'success'
263+
).then(function() {
264+
$scope.func_show_all_task()
265+
});
266+
},
267+
error: function (jqXHR, exception) {
268+
Swal.fire({
269+
icon: "error",
270+
title: jqXHR.status + ' ' + jqXHR.statusText ,
271+
text: jqXHR.responseText,
272+
});
273+
}
274+
});
275+
}
276+
});
277+
}
278+
$scope.func_edit_task = function(guid) {
279+
ShowLoading(true);
280+
$window.location.href = '/task/edit?guid='+ guid;
237281
}
238282
$scope.init();
239283
});
240284
</script>
241-
{% endblock %}
285+
286+
{% endblock %}

django/Templates/log.index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ <h3>Log Task</h3>
6262
$scope.init = function () {
6363
$scope.funcGetLogs();
6464

65-
setInterval(function(){
66-
$scope.funcGetLogs();
67-
}, 2000);
65+
// setInterval(function(){
66+
// $scope.funcGetLogs();
67+
// }, 2000);
6868
};
6969

7070
$scope.funcBtnBack = function(){
@@ -96,6 +96,7 @@ <h3>Log Task</h3>
9696
'Your file has been deleted.',
9797
'success'
9898
);
99+
$scope.funcGetLogs();
99100
},
100101
error: function (jqXHR, exception) {
101102
Swal.fire({

0 commit comments

Comments
 (0)