create, update, remove cron job for ci task
This commit is contained in:
+1
-1
@@ -77,4 +77,4 @@ CREATE TABLE `zt_cibuild` (
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES
|
||||
('*/5', '*', '*', '*', '*', 'moduleName=ci&methodName=checkCibuild', '同步Jenkins任务状态', 'zentao', 0, 'stop', '0000-00-00 00:00:00');
|
||||
('*/5', '*', '*', '*', '*', 'moduleName=ci&methodName=checkCibuild', '同步Jenkins任务状态', 'zentao', 1, 'normal', '0000-00-00 00:00:00');
|
||||
|
||||
@@ -328,6 +328,9 @@ class ci extends control
|
||||
$this->ci->delete(TABLE_CI_TASK, $id);
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$command = 'moduleName=ci&methodName=exeCitask&id=' . $id;
|
||||
$this->dao->delete()->from(TABLE_CRON)->where('command')->eq($command)->exec();
|
||||
|
||||
$this->send(array('result' => 'success'));
|
||||
}
|
||||
|
||||
@@ -355,6 +358,8 @@ class ci extends control
|
||||
*/
|
||||
public function checkCibuild()
|
||||
{
|
||||
error_log("checkCibuild...");
|
||||
|
||||
$this->ci->checkCibuild();
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
|
||||
@@ -21,26 +21,14 @@ function triggerTypeChanged(type) {
|
||||
$('.tag-fields').addClass('hidden');
|
||||
$('.comment-fields').addClass('hidden');
|
||||
|
||||
var val = $("input[name='scheduleType']:checked").val();
|
||||
scheduleTypeChanged(val? val: 'corn');
|
||||
scheduleTypeChanged('custom');
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleTypeChanged(type) {
|
||||
if(type == 'corn') {
|
||||
$('.schedule-fields').removeClass('hidden');
|
||||
|
||||
$('.corn-fields').removeClass('hidden');
|
||||
$('.custom-fields').addClass('hidden');
|
||||
} else if(type == 'custom') {
|
||||
$('.schedule-fields').removeClass('hidden');
|
||||
|
||||
$('.corn-fields').addClass('hidden');
|
||||
if(type == 'custom') {
|
||||
$('.custom-fields').removeClass('hidden');
|
||||
} else {
|
||||
$('.schedule-fields').addClass('hidden');
|
||||
|
||||
$('.corn-fields').addClass('hidden');
|
||||
$('.custom-fields').addClass('hidden');
|
||||
}
|
||||
}
|
||||
@@ -35,26 +35,14 @@ function triggerTypeChanged(type) {
|
||||
$('.tag-fields').addClass('hidden');
|
||||
$('.comment-fields').addClass('hidden');
|
||||
|
||||
var val = $("input[name='scheduleType']:checked").val();
|
||||
scheduleTypeChanged(val? val: 'corn');
|
||||
scheduleTypeChanged('custom');
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleTypeChanged(type) {
|
||||
if(type == 'corn') {
|
||||
$('.schedule-fields').removeClass('hidden');
|
||||
|
||||
$('.corn-fields').removeClass('hidden');
|
||||
$('.custom-fields').addClass('hidden');
|
||||
} else if(type == 'custom') {
|
||||
$('.schedule-fields').removeClass('hidden');
|
||||
|
||||
$('.corn-fields').addClass('hidden');
|
||||
if(type == 'custom') {
|
||||
$('.custom-fields').removeClass('hidden');
|
||||
} else {
|
||||
$('.schedule-fields').addClass('hidden');
|
||||
|
||||
$('.corn-fields').addClass('hidden');
|
||||
$('.custom-fields').addClass('hidden');
|
||||
}
|
||||
}
|
||||
@@ -76,11 +76,12 @@ $lang->citask->custom = '自定义';
|
||||
|
||||
$lang->citask->tagKeywords = '标签关键字';
|
||||
$lang->citask->commentKeywords = '注释关键字';
|
||||
$lang->citask->extTask = '执行任务';
|
||||
|
||||
$lang->citask->at = '在';
|
||||
$lang->citask->time = '时间';
|
||||
$lang->citask->exe = '执行';
|
||||
$lang->citask->scheduleInterval = '间隔';
|
||||
$lang->citask->scheduleInterval = '每隔';
|
||||
$lang->citask->scheduleDay = '天数';
|
||||
$lang->citask->day = '天';
|
||||
$lang->citask->lastExe = '最后执行';
|
||||
|
||||
+44
-2
@@ -210,6 +210,7 @@ class ciModel extends model
|
||||
public function createCitask()
|
||||
{
|
||||
$task = fixer::input('post')
|
||||
->add('scheduleType', 'custom')
|
||||
->add('createdBy', $this->app->user->account)
|
||||
->add('createdDate', helper::now())
|
||||
->get();
|
||||
@@ -219,11 +220,30 @@ class ciModel extends model
|
||||
->batchCheckIF($task->triggerType === 'tag', "tagKeywords", 'notempty')
|
||||
->batchCheckIF($task->triggerType === 'commit', "commentKeywords", 'notempty')
|
||||
|
||||
->batchCheckIF($task->triggerType === 'schedule' && $task->scheduleType == 'corn', "cornExpression", 'notempty')
|
||||
->batchCheckIF($task->triggerType === 'schedule' && $task->scheduleType == 'custom', "scheduleDay,scheduleTime,scheduleInterval", 'notempty')
|
||||
|
||||
->autoCheck()
|
||||
->exec();
|
||||
|
||||
if ($task->triggerType === 'schedule' && $task->scheduleType == 'custom') {
|
||||
$arr = explode(":", $task->scheduleTime);
|
||||
$hour = $arr[0];
|
||||
$min = $arr[1];
|
||||
|
||||
$taskId = $this->dao->lastInsertID();
|
||||
if ($task->scheduleDay == 'everyDay') {
|
||||
$days = '1-7';
|
||||
} else if ($task->scheduleDay == 'workDay') {
|
||||
$days = '1-5';
|
||||
}
|
||||
|
||||
$cron = (object) array('m'=>$min, 'h'=>$hour, 'dom'=>'*', 'mon'=>'*',
|
||||
'dow'=> $days . '/' . $task->scheduleInterval, 'command'=>'moduleName=ci&methodName=exeCitask&id=' . $taskId,
|
||||
'remark'=>($this->lang->citask->extTask . $taskId), 'type'=>'zentao',
|
||||
'buildin'=>'-1', 'status'=>'normal', 'lastTime'=>'0000-00-00 00:00:00');
|
||||
$this->dao->insert(TABLE_CRON)->data($cron)->exec();
|
||||
}
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
@@ -237,6 +257,7 @@ class ciModel extends model
|
||||
public function updateCitask($id)
|
||||
{
|
||||
$task = fixer::input('post')
|
||||
->add('scheduleType', 'custom')
|
||||
->add('editedBy', $this->app->user->account)
|
||||
->add('editedDate', helper::now())
|
||||
->get();
|
||||
@@ -246,12 +267,33 @@ class ciModel extends model
|
||||
->batchCheckIF($task->triggerType === 'tag', "tagKeywords", 'notempty')
|
||||
->batchCheckIF($task->triggerType === 'commit', "commentKeywords", 'notempty')
|
||||
|
||||
->batchCheckIF($task->triggerType === 'schedule' && $task->scheduleType == 'corn', "cornExpression", 'notempty')
|
||||
->batchCheckIF($task->triggerType === 'schedule' && $task->scheduleType == 'custom', "scheduleDay,scheduleTime,scheduleInterval", 'notempty')
|
||||
|
||||
->autoCheck()
|
||||
->where('id')->eq($id)
|
||||
->exec();
|
||||
|
||||
if ($task->triggerType === 'schedule' && $task->scheduleType == 'custom') {
|
||||
$arr = explode(":", $task->scheduleTime);
|
||||
$hour = $arr[0];
|
||||
$min = $arr[1];
|
||||
|
||||
$taskId = $this->dao->lastInsertID();
|
||||
if ($task->scheduleDay == 'everyDay') {
|
||||
$days = '1-7';
|
||||
} else if ($task->scheduleDay == 'workDay') {
|
||||
$days = '1-5';
|
||||
}
|
||||
$command = 'moduleName=ci&methodName=exeCitask&id=' . $id;
|
||||
|
||||
$this->dao->update(TABLE_CRON)
|
||||
->set('m')->eq($min)
|
||||
->set('h')->eq($hour)
|
||||
->set('dow')->eq($days . '/' . $task->scheduleInterval)
|
||||
->set('lastTime')->eq('0000-00-00 00:00:00')
|
||||
->where('command')->eq($command)->exec();
|
||||
}
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,6 @@
|
||||
<th><?php echo $lang->citask->triggerType; ?></th>
|
||||
<td><?php echo html::select('triggerType', $lang->citask->triggerTypeList, '',
|
||||
"onchange='triggerTypeChanged(this.value)' class='form-control chosen'"); ?></td>
|
||||
|
||||
<th class="schedule-fields"><?php echo $lang->citask->scheduleType; ?></th>
|
||||
<td class="schedule-fields"><?php echo html::radio('scheduleType', $lang->citask->scheduleTypeList, 'corn',
|
||||
"onclick='scheduleTypeChanged(this.value)'");?></td>
|
||||
</tr>
|
||||
<tr class="tag-fields">
|
||||
<th><?php echo $lang->citask->tagKeywords; ?></th>
|
||||
@@ -62,11 +58,6 @@
|
||||
<td colspan="2"><span style="font-style: italic">build_now</span></td>
|
||||
</tr>
|
||||
|
||||
<tr class="corn-fields">
|
||||
<th><?php echo $lang->citask->cornExpression; ?></th>
|
||||
<td><?php echo html::input('cornExpression', '', "class='form-control'"); ?></td>
|
||||
<td colspan="2"><span style="font-style: italic">0 0 2 * * ?</span></td>
|
||||
</tr>
|
||||
<tr class="custom-fields">
|
||||
<th><?php echo $lang->citask->custom; ?></th>
|
||||
<td colspan="3">
|
||||
|
||||
@@ -48,10 +48,6 @@
|
||||
<th><?php echo $lang->citask->triggerType; ?></th>
|
||||
<td><?php echo html::select('triggerType', $lang->citask->triggerTypeList, $citask->triggerType,
|
||||
"onchange='triggerTypeChanged(this.value)' class='form-control chosen'"); ?></td>
|
||||
|
||||
<th class="schedule-fields"><?php echo $lang->citask->scheduleType; ?></th>
|
||||
<td class="schedule-fields"><?php echo html::radio('scheduleType', $lang->citask->scheduleTypeList, $citask->scheduleType,
|
||||
"onclick='scheduleTypeChanged(this.value)'");?></td>
|
||||
</tr>
|
||||
<tr class="tag-fields">
|
||||
<th><?php echo $lang->citask->tagKeywords; ?></th>
|
||||
@@ -64,11 +60,6 @@
|
||||
<td colspan="2"><span style="font-style: italic">build_now</span></td>
|
||||
</tr>
|
||||
|
||||
<tr class="corn-fields">
|
||||
<th><?php echo $lang->citask->cornExpression; ?></th>
|
||||
<td><?php echo html::input('cornExpression', $citask->cornExpression, "class='form-control'"); ?></td>
|
||||
<td colspan="2"><span style="font-style: italic">0 0 2 * * ?</span></td>
|
||||
</tr>
|
||||
<tr class="custom-fields">
|
||||
<th><?php echo $lang->citask->custom; ?></th>
|
||||
<td colspan="3">
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<td class='text-center'>
|
||||
<?php
|
||||
if(common::hasPriv('cron', 'toggle') and !empty($cron->command)) echo html::a(inlink('toggle', "id=$cron->id&status=" . ($cron->status == 'stop' ? 'normal' : 'stop')), $cron->status == 'stop' ? $lang->cron->toggleList['start'] : $lang->cron->toggleList['stop'], 'hiddenwin');
|
||||
if(!empty($cron->command) and common::hasPriv('cron', 'edit')) echo html::a(inlink('edit', "id=$cron->id"), $lang->edit);
|
||||
if(!empty($cron->command) and common::hasPriv('cron', 'edit') and $cron->buildin >= 0) echo html::a(inlink('edit', "id=$cron->id"), $lang->edit);
|
||||
if($cron->buildin == 0 and common::hasPriv('cron', 'delete')) echo html::a(inlink('delete', "id=$cron->id"), $lang->delete, 'hiddenwin');
|
||||
?>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user