cron.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | role.php 角色表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $option = array
  9. (
  10. 1 => '可执行',
  11. 2 => '已完成',
  12. );
  13. $info = Dever::load('manage/project.get');
  14. $path = $info['manage']['path'];
  15. if(isset($info['manage']['setup']))
  16. {
  17. $path = $info['manage']['setup'];
  18. }
  19. # 获取project
  20. $project = function() use ($info)
  21. {
  22. $data = array();
  23. foreach($info as $k => $v)
  24. {
  25. //$k = $v['lib'];
  26. if (isset($v['lang']) && isset($v['name'])) {
  27. $data[$k]['id'] = $v['name'];
  28. $data[$k]['name'] = $v['lang'] . '('.$v['name'].')';
  29. }
  30. }
  31. return $data;
  32. };
  33. return array
  34. (
  35. # 表名
  36. 'name' => 'cron',
  37. # 显示给用户看的名称
  38. 'lang' => '计划任务',
  39. 'desc' => Dever::markdown('**启动cron的方法,以下三项任选其一:**
  40. 1. 常规任务:请将 ```* * * * * root php '.$path.'daemon/main.php``` 放到cron中[建议每分钟执行一次]
  41. 2. 用户触发:请在 ```config/base.php里开启cron=true``` [一般适用于虚拟主机]
  42. 3. 长期运行:请执行 ```php '.$path.'daemon/loop.php 1>/dev/null 2>&1 &``` 指令,放置后台运行[一般用于队列等需要长期运行的项目]'),
  43. # 数据结构
  44. 'struct' => array
  45. (
  46. 'id' => array
  47. (
  48. 'type' => 'int-11',
  49. 'name' => 'ID',
  50. 'default' => '',
  51. 'desc' => '',
  52. 'match' => 'is_numeric',
  53. 'search' => 'order',
  54. 'list' => true,
  55. ),
  56. 'name' => array
  57. (
  58. 'type' => 'varchar-32',
  59. 'name' => '任务名',
  60. 'default' => '',
  61. 'desc' => '请输入任务名',
  62. 'match' => 'is_string',
  63. 'update' => 'text',
  64. 'search' => 'fulltext',
  65. 'list' => true,
  66. ),
  67. 'project' => array
  68. (
  69. 'type' => 'varchar-30',
  70. 'name' => '项目',
  71. 'default' => '',
  72. 'desc' => '请选择项目',
  73. 'match' => 'is_string',
  74. 'update' => 'select',
  75. 'option' => $project,
  76. 'list' => true,
  77. ),
  78. 'interface' => array
  79. (
  80. 'type' => 'varchar-100',
  81. 'name' => '接口(命令行)',
  82. 'default' => '',
  83. 'desc' => '请输入接口(命令行)',
  84. 'match' => 'is_string',
  85. 'update' => 'text',
  86. ),
  87. 'ldate' => array
  88. (
  89. 'type' => 'int-11',
  90. 'name' => '执行时间',
  91. 'match' => 'is_numeric',
  92. 'desc' => '请选择执行时间',
  93. 'update' => 'date',
  94. 'callback' => 'maketime',
  95. 'list' => 'date("Y-m-d H:i:s", {ldate})',
  96. ),
  97. 'time' => array
  98. (
  99. 'type' => 'int-11',
  100. 'name' => '时间间隔(为0则执行一次)',
  101. 'default' => '0',
  102. 'match' => 'is_numeric',
  103. 'desc' => '请输入时间间隔',
  104. 'update' => 'text',
  105. 'list' => true,
  106. ),
  107. 'state' => array
  108. (
  109. 'type' => 'tinyint-1',
  110. 'name' => '状态',
  111. 'default' => '1',
  112. 'desc' => '请选择状态',
  113. 'match' => 'is_numeric',
  114. 'option' => $option,
  115. 'update' => 'radio',
  116. 'list' => true,
  117. ),
  118. 'cdate' => array
  119. (
  120. 'type' => 'int-11',
  121. 'name' => '录入时间',
  122. 'match' => array('is_numeric', time()),
  123. 'desc' => '',
  124. # 只有insert时才生效
  125. 'insert' => true,
  126. //'list' => 'date("Y-m-d H:i:s", {cdate})',
  127. ),
  128. ),
  129. 'manage' => array
  130. (
  131. //'delete' => false
  132. ),
  133. # request 请求接口定义
  134. 'request' => array
  135. (
  136. # get
  137. 'get' => array
  138. (
  139. 'where' => array
  140. (
  141. 'ldate' => array('yes', '<='),
  142. 'state' => 1,
  143. ),
  144. 'type' => 'all',
  145. 'order' => array('id', 'desc'),
  146. 'col' => '*',
  147. ),
  148. # get
  149. 'getOne' => array
  150. (
  151. 'where' => array
  152. (
  153. 'project' => 'yes',
  154. 'interface' => 'yes',
  155. ),
  156. 'type' => 'one',
  157. ),
  158. ),
  159. );