[WordPress] 外掛分享: Async Background Worker

前言介紹

  • 這款 WordPress 外掛「Async Background Worker」是 2017-12-21 上架。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2017-12-27,距離現在已有 2685 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.4 以上版本才可以安裝。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

gamaup | todiadiatmo |

外掛標籤

background worker | async background worker |

內容簡介

Async Background Worker 是一款 WordPress 外掛,詳細資訊請參閱此頁面 https://tonjoo.github.io/async-background-worker/

範例使用
這是什麼?

這是一款 WordPress 背景工作外掛,能夠讓 WordPress 與 beanstalkd 工作隊列互動。

為什麼需要工作隊列?

當我們需要在後台執行非常耗時的工作時,舉例來說,需要將 100,000 行資料匯入 WordPress 資料庫。我們可以將此任務分成多個較小的任務,這樣較為安全。

WP-CLI

確定您系統已安裝 WP CLI。

支援論壇

https://forum.tonjoostudio.com/thread-category/async-background-worker/

新增工作至隊列

使用 add_async_job 命令將新工作新增至新工作者隊列

$job = new stdClass();
// 要執行的函式
$job->function = 'function_to_execute_on_background';
// 使用者輸入的資料
$job->user_data = array('data'=>'some_data');
add_async_job($job);

實作函式

function function_to_execute_on_background($data) {
// 做一些有用的事
echo "背景工作已成功執行\n";
}

執行 wp background-worker listen

命令

wp background-worker
執行 Async Background Worker 一次。

wp background-worker listen
連續執行 Async Background Worker,這是後台工作者想要的。WordPress 框架在每個迴圈中都會重新啟動。

wp background-worker listen-daemon
連續執行 Async Background Worker 而不重新啟動 WordPress 框架。請注意,如果您使用這種模式,任何程式碼變更都不會反映出來。在更改程式碼時,必須每次重新啟動 Async Background Worker。這樣可以節省記憶體並加快速度。

原文外掛簡介

Async Background Worker, more information please visit this page https://tonjoo.github.io/async-background-worker/
Sample Usage
What is it ?
WordPress background worker plugin that enable WordPress to interact with beanstalkd work queue.
Why we need a worker ?
We can run a very long task in the background, for example we need to import 100.000 row into WordPress databases. Instead of doing the 100.000 import in one job, we can separate the job into many smaller job which is safer.
WP-CLI
Make sure you have WP CLI installed on your system
Support Forum
https://forum.tonjoostudio.com/thread-category/async-background-worker/
Add job to queue

Add new job to new worker queue using add_async_job command
$job = new stdClass();
// the function to run
$job->function = 'function_to_execute_on_background';
// our user entered data
$job->user_data = array('data'=>'some_data');
add_async_job($job);

Implement function
function function_to_execute_on_background($data) {
//do something usefull
echo "Background job executed successfully\n";
}

Run wp background-worker listen

Command

wp background-worker
Run Async Background Worker once.

wp background-worker listen
Run Async Background Worker in loop (contiously), this is what you want for background worker. WordPress framework is restart in each loop.

wp background-worker listen-daemon
Run Async Background Worker in loop (contiously) without restart the WordPress framework. NOTE if you use this mode, any code change will not be reflected. You must restart the Async Background Worker each time you change code. This save memory and speed up thing.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Async Background Worker」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


最新版本

延伸相關外掛(你可能也想知道)

暫無相關外掛推薦。

文章
Filter
Apply Filters
Mastodon