Industry 4.0 environments are characterized by an explosion in the number of mobile devices, generating massive data and computation demands. Edge computing allows IoT devices to offload tasks to the edge environment for execution in order to fulfill the task’s demand for resources. To achieve real-time control of the edge computing environment, this study proposes a deep reinforcement learning-based task offloading and resource allocation method. The method uses the Lagrange multiplier method to solve for the optimal allocation of resources and the DDPG algorithm to search for the optimal offloading decision method. Experiments show that the method in this paper outperforms the baseline algorithm in terms of cumulative rewards and task discarding rate, meanwhile, it can significantly improve the throughput of the system while reducing the latency and energy consumption, with the former improved by 9.98%~28.61% and the latter two reduced by 8.05%~22.48% and 4.45%~16.05%, which can effectively improve the efficiency of task offloading and resource allocation in edge environments,. It has high real-time performance and good dynamic environment adaptability.