Files
crawlab/documentation/Architecture/TaskExecution.md
2019-12-05 12:06:38 +08:00

14 lines
1017 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 任务执行
Crawlab的任务执行依赖于shell。执行一个爬虫任务相当于在shell中执行相应的命令因此在执行爬虫任务之前要求使用者将执行命令存入数据库。执行命令存在`spiders`表中的`cmd`字段。
任务执行的架构示意图如下。
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/v0.3.0/task-execution.png)
当爬虫任务被派发时主节点会在Redis中的`tasks:<node_id>`(指定工作节点)和`tasks:public`(任意工作节点)派发任务,也就是`RPUSH`命令。
工作节点在启动时会起N个执行器通过环境变量`CRAWLAB_TASK_WORKERS`配置默认为4每个执行器会轮训Redis的消息队列优先获取指定节点消息队列`tasks:<node_id>`,如果指定队列中没有任务,才会获取任意节点消息队列中的任务`tasks:public`
执行过程的具体情况就不细述了,详情请见[源码](https://github.com/tikazyq/crawlab/blob/master/backend/services/task.go)。