Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ic_server_welfare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
55c5d40d
authored
Sep 27, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改重置任务å的方式
parent
7decbc26
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
5 deletions
.env
app/Jobs/Timer/ResetExchangeSettingsCronJob.php
config/laravels.php
storage/laravels.json
storage/laravels.pid
.env
View file @
55c5d40d
...
...
@@ -48,4 +48,5 @@ IC_AUTH_API=http://authapi.icsales.cc
RobotUrl=https://oapi.dingtalk.com/robot/send?access_token=a7255513c160f20d65c0c00d939fe88712233bbda0dc520563705bf721072d11
LARAVELS_TIMER = true
app/Jobs/Timer/ResetExchangeSettingsCronJob.php
0 → 100644
View file @
55c5d40d
<?php
namespace
App\Jobs\Timer
;
use
Carbon\Carbon
;
use
Common\Model\RedisModel
;
use
Hhxsv5\LaravelS\Swoole\Timer\CronJob
;
use
Illuminate\Support\Facades\Log
;
use
Swoole\Coroutine
;
class
ResetExchangeSettingsCronJob
extends
CronJob
{
// protected $i = 0;
// !!! 定时任务的`interval`和`isImmediate`有两种配置方式(二选一):一是重载对应的方法,二是注册定时任务时传入参数。
// --- 重载对应的方法来返回配置:开始
public
function
interval
()
{
return
1000
;
// 每1秒运行一次
}
public
function
isImmediate
()
{
return
true
;
// 是否立即执行第一次,false则等待间隔时间后执行第一次
}
// --- 重载对应的方法来返回配置:结束
public
function
run
()
{
//判断是否是10点,如果是10点就进行重置任务
$time
=
Carbon
::
create
(
null
,
null
,
null
,
13
,
55
);
$time
=
$time
->
timestamp
;
$now
=
Carbon
::
now
()
->
timestamp
;
if
(
$time
===
$now
)
{
Log
::
info
(
"进行定时检测重置任务..."
);
$this
->
reset
();
}
}
private
function
reset
(){
Log
::
info
(
"开始重置..."
);
//重置商品可兑换限额
//先从redis缓存里面去取需要的数据
$redis
=
new
RedisModel
();
$settings
=
$redis
->
hgetall
(
'ic_exchange_settings'
);
//获取到所有配置项之后,就要根据配置项里面的stock字段更新对应的列表
//列表形式为ic_exchange_setting_{$id},然后这个键是list类型,里面简单存1就好
try
{
foreach
(
$settings
as
$key
=>
$setting
)
{
$setting
=
json_decode
(
$setting
,
true
);
$id
=
$setting
[
'id'
];
//先去删除原有的
$redis
->
del
(
'ic_exchange_settings_'
.
$id
);
$data
=
array_fill
(
0
,
$setting
[
'stock'
],
1
);
$redis
->
lpush
(
'ic_exchange_settings_'
.
$id
,
$data
);
}
}
catch
(
\Exception
$e
)
{
Log
::
info
(
"重置失败,原因是"
.
$e
);
return
;
}
Log
::
info
(
"重置完成"
);
}
}
\ No newline at end of file
config/laravels.php
View file @
55c5d40d
...
...
@@ -32,13 +32,13 @@ return [
//],
],
'timer'
=>
[
'enable'
=>
true
,
'enable'
=>
env
(
'LARAVELS_TIMER'
)
,
'jobs'
=>
[
// Enable LaravelScheduleJob to run `php artisan schedule:run` every 1 minute, replace Linux Crontab
\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob
::
class
,
//
\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob::class,
// Two ways to configure parameters:
// [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering
// \App\Jobs\Xxx
CronJob::class, // Override the corresponding method to return the configuration
\App\Jobs\Timer\ResetExchangeSettings
CronJob
::
class
,
// Override the corresponding method to return the configuration
],
'max_wait_time'
=>
5
,
],
...
...
storage/laravels.json
View file @
55c5d40d
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
55c5d40d
2170
\ No newline at end of file
12787
\ No newline at end of file
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