webman_ad/app/process/UpdateGoogleAdsTask.php
2025-02-08 21:35:32 +08:00

119 lines
3.9 KiB
PHP

<?php
namespace app\process;
use app\event\GoogleAdsCampaigns;
use app\event\GoogleAdsCreatives;
use app\event\GoogleAdsCustomers;
use app\event\GoogleAdsGroups;
use app\event\GoogleAdsAds;
use app\event\GoogleAdsAssets;
use app\event\GoogleAdsAssetRelations;
use app\event\GoogleAdsDateDatas;
use Webman\Event\Event;
use Workerman\Crontab\Crontab;
/**
* 更新热搜列表任务
*/
class UpdateGoogleAdsTask
{
//错开时间执行,否则固定时间段接口会响应很慢
public function onWorkerStart()
{
// 每15分钟执行一次
new Crontab('10 15 */2 * * *', function () {
$dayBeforeYesterdayStart = date('Y-m-d', strtotime('-2 day'));
dump($dayBeforeYesterdayStart . '更新' . GoogleAdsDateDatas::event . '开始');
Event::emit(GoogleAdsDateDatas::event, ['date' => $dayBeforeYesterdayStart]);
}
);
// 每15分钟执行一次
new Crontab('20 14 */2 * * *', function () {
$yesterdayStart = date('Y-m-d', strtotime('-1 day'));
dump($yesterdayStart . '更新' . GoogleAdsDateDatas::event . '开始');
Event::emit(GoogleAdsDateDatas::event, ['date' => $yesterdayStart]);
}
);
// 每15分钟执行一次
new Crontab('30 13 */2 * * *', function () {
//获取今天的 0 点的YYYY - MM - DD格式
$todayStart = date('Y-m-d', strtotime('0 day'));
dump($todayStart . '更新' . GoogleAdsDateDatas::event . '开始');
Event::emit(GoogleAdsDateDatas::event, ['date' => $todayStart]);
}
);
// 每15分钟执行一次
new Crontab('15 12 */2 * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAssetRelations::event . '开始');
Event::emit(GoogleAdsAssetRelations::event, []);
}
);
// 每15分钟执行一次
new Crontab('30 * */2 * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsGroups::event . '开始');
Event::emit(GoogleAdsGroups::event, []);
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::event . '开始');
Event::emit(GoogleAdsCampaigns::event, []);
}
);
// 每15分钟执行一次
new Crontab('5 * */2 * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAds::event . '开始');
Event::emit(GoogleAdsAds::event, []);
}
);
// 每15分钟执行一次
new Crontab('25 12 */3 * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCreatives::event . '开始');
Event::emit(GoogleAdsCreatives::event, []);
}
);
new Crontab('25 11 */2 * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAssets::event . '开始');
Event::emit(GoogleAdsAssets::event, []);
}
);
new Crontab('16 */14 * * * *', function () {
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCustomers::event . '开始');
Event::emit(GoogleAdsCustomers::event, []);
}
);
// 每15分钟执行一次
// new Crontab('58 */15 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始');
// Event::emit(GoogleAdsCampaigns::type, ['customer_id'=>4060397299]);
//
// });
// 每30分钟执行一次
// new Crontab('0 */30 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . V2ex::type . '开始');
// Event::emit(V2ex::type, null);
//
// dump(date('Y-m-d H:i:s') . '更新' . GitHub::type . '开始');
// Event::emit(GitHub::type, null);
//
// dump(date('Y-m-d H:i:s') . '更新' . JueJin::type . '开始');
// Event::emit(JueJin::type, null);
// });
}
}