crontab中的django-cron作业无法正常工作?

时间:2019-03-05 21:30:03

标签: python django cron virtualenv

当我发出以下命令时,我是django-cron库:

@SpringBootTest(classes = { TestConfig.class })
@ActiveProfiles("test")
@Profile("test")
@RunWith(SpringJUnit4ClassRunner.class)
public class TestClass {

 @Autowired
 private RestTemplate restTemplate;

  @Test
  public void taskTest() {

    //code

    given(this.restTemplate.exchange(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(),
        ArgumentMatchers.isA(new ParameterizedTypeReference<TestData1>() {
        }.getClass()))).willReturn(ResponseEntity.accepted().body(new TestData1()));

given(this.restTemplate.exchange(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(),
        ArgumentMatchers.isA(new ParameterizedTypeReference<TestData2>() {
        }.getClass()))).willReturn(ResponseEntity.accepted().body(new TestData2()));

given(this.restTemplate.exchange(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(),
        ArgumentMatchers.isA(new ParameterizedTypeReference<List<TestData3>>() {
    }.getClass()))).willReturn(ResponseEntity.accepted().body(Arrays.asList(new TestData3())));

 //code
  }

它运行正常,但是在corntab中设置它时不起作用。我在corntab中使用了以下cornjob:

python manage.py runcrons

SHELL=/bin/bash */1 * * * * root source /var/path_to_venv/bin/activate && cd /var/path_to_project && /usr/bin/python3.6 /var/path_to_project/manage.py runcrons --settings Project.settings.production > /var/log/cronjob.log 2>&1 文件始终为空。关于这个问题的原因有什么想法吗?

0 个答案:

没有答案