Commit 55c5d40d by 杨树贤

修改重置任务å的方式

parent 7decbc26
...@@ -48,4 +48,5 @@ IC_AUTH_API=http://authapi.icsales.cc ...@@ -48,4 +48,5 @@ IC_AUTH_API=http://authapi.icsales.cc
RobotUrl=https://oapi.dingtalk.com/robot/send?access_token=a7255513c160f20d65c0c00d939fe88712233bbda0dc520563705bf721072d11 RobotUrl=https://oapi.dingtalk.com/robot/send?access_token=a7255513c160f20d65c0c00d939fe88712233bbda0dc520563705bf721072d11
LARAVELS_TIMER = true
<?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
...@@ -32,13 +32,13 @@ return [ ...@@ -32,13 +32,13 @@ return [
//], //],
], ],
'timer' => [ 'timer' => [
'enable' => true, 'enable' => env('LARAVELS_TIMER'),
'jobs' => [ 'jobs' => [
// Enable LaravelScheduleJob to run `php artisan schedule:run` every 1 minute, replace Linux Crontab // 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: // Two ways to configure parameters:
// [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering // [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering
// \App\Jobs\XxxCronJob::class, // Override the corresponding method to return the configuration \App\Jobs\Timer\ResetExchangeSettingsCronJob::class, // Override the corresponding method to return the configuration
], ],
'max_wait_time' => 5, 'max_wait_time' => 5,
], ],
......
2170 12787
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment