Considerable research has been dedicated to exploring the fog computing model, which aims to improve cloud-based services for Internet of Things (IoT) and AI users. The model introduces a fog layer between the user and cloud layers to minimize data transmission and processing time while controlling expenses. Nevertheless, the use of virtualization technologies in fog planning and resource management has faced challenges due to resource constraints and delayed services. To overcome these obstacles, this paper introduces a novel task scheduling algorithm called Task Priority Dynamic Implementation (TPDI) that leverages priority levels within the fog layer. The primary objective of this algorithm is to enhance the timely execution of tasks and reduce costs, particularly given the increasing number of IoT devices and AI-powered intelligent systems. The performance evaluations demonstrate that TPDI outperforms existing task scheduling algorithms by reducing overall response times. This development holds significant importance for emerging brownfield computing technology, as we anticipate that the priority algorithm can find applications in various domains.