Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
a8f32632
Commit
a8f32632
authored
Nov 03, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成清理不使用的文件计划任务
parent
5313d7bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
0 deletions
+73
-0
UploadPools.php
src/common/models/UploadPools.php
+12
-0
MaintainController.php
src/console/controllers/MaintainController.php
+56
-0
WithdrawController.php
src/console/controllers/WithdrawController.php
+5
-0
No files found.
src/common/models/UploadPools.php
View file @
a8f32632
...
...
@@ -163,5 +163,17 @@ class UploadPools extends ActiveRecord
return
false
;
}
/**
* 返回不在使用的文件列表
*
* @param int $limit
* @return UploadPools[]
*/
public
static
function
fetchUnusedFiles
(
$limit
=
500
)
{
return
self
::
find
()
->
select
(
'uuid,skey'
)
->
where
(
'`status` IN (0,2) AND upload_time<:expire'
,
[
':expire'
=>
time
()
-
86400
])
->
limit
(
$limit
)
->
all
();
}
}
\ No newline at end of file
src/console/controllers/MaintainController.php
0 → 100644
View file @
a8f32632
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2016/11/3
* Time: 17:57
*/
namespace
console\controllers
;
use
common\models\UploadPools
;
use
Qiniu\Storage\BucketManager
;
use
yii\console\Controller
;
class
MaintainController
extends
Controller
{
/**
* 清理长期未被认领或已指定要删除的文件
*
* 建议每隔2-5个小时运行一次
*
* @throws \Exception
*/
public
function
actionClearUploadPool
()
{
/* @var $qiniu \common\components\Qiniu */
$qiniu
=
\Yii
::
$app
->
qiniu
;
$auth
=
$qiniu
->
getAuthInstance
();
$bucketMgr
=
new
BucketManager
(
$auth
);
$list
=
UploadPools
::
fetchUnusedFiles
();
$success
=
$failed
=
0
;
foreach
(
$list
as
$file
)
{
list
(
$storage
,
$key
)
=
explode
(
':'
,
$file
->
skey
);
$bucket
=
$qiniu
->
getStorageConfig
(
$storage
,
'bucket'
);
/* @var $err \Qiniu\Http\Error */
$err
=
$bucketMgr
->
delete
(
$bucket
,
$key
);
if
(
$err
==
null
||
$err
->
getResponse
()
->
statusCode
==
612
)
{
$file
->
delete
();
++
$success
;
}
else
{
++
$failed
;
\Yii
::
warning
(
'Delete unused file failed: '
.
$err
->
message
()
.
"
\n
{
uuid={$file->uuid
}
, skey=
{
$file
->
skey
}
"
);
}
}
$info
=
"Deleted unused files finish, success=
$success
, failed=
$failed
."
;
\Yii
::
info
(
$info
);
echo
$info
.
"
\n
"
;
}
}
\ No newline at end of file
src/console/controllers/WithdrawController.php
View file @
a8f32632
...
...
@@ -25,6 +25,11 @@ use yii\console\Controller;
class
WithdrawController
extends
Controller
{
/**
* 结算今日之前用户的收入
*
* 建议每次凌晨或上午运行
*/
public
function
actionSettle
()
{
$this
->
actionCreateSettleOrders
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment