Skip to content

Cron job is sometimes triggered twice in a row  #38

@rdelgatte

Description

@rdelgatte

Hello

First of all, thank you for this very useful library I recently started to work with.

I am experiencing some troubles when scheduling a simple job to start every minutes as it sometimes starts two threads within the same second.

ThreadId 20 at 2019-12-13 13:37:59.999691 UTC
ThreadId 21 at 2019-12-13 13:38:00.001119 UTC

I tried to reproduce in a standalone / simple example which is the following:

module Example where

import           Control.Concurrent (myThreadId)
import           Data.Time          (getCurrentTime)
import           System.Cron

runApplication :: IO ()
runApplication = do
  threadIds <- execSchedule setupCronJob
  putStrLn $ "Scheduling job " <> show threadIds <> " is running"
  _ <- getLine
  -- to stop only when the user types
  pure ()

setupCronJob :: Schedule ()
setupCronJob = addJob runJob "* * * * *"

runJob :: IO ()
runJob = do
  threadId <- myThreadId
  currentTime <- getCurrentTime
  putStrLn $ show threadId <> " at " <> show currentTime

This example triggers a job which prints the threadId with the current execution time and I get the following output:

Scheduling job [ThreadId 12] is running
ThreadId 13 at 2019-12-13 13:31:00.004439 UTC
ThreadId 14 at 2019-12-13 13:32:00.003727 UTC
ThreadId 15 at 2019-12-13 13:33:00.003082 UTC
ThreadId 16 at 2019-12-13 13:34:00.000189 UTC
ThreadId 17 at 2019-12-13 13:35:00.001204 UTC
ThreadId 18 at 2019-12-13 13:36:00.002054 UTC
ThreadId 19 at 2019-12-13 13:37:00.001719 UTC
ThreadId 20 at 2019-12-13 13:37:59.999691 UTC
ThreadId 21 at 2019-12-13 13:38:00.001119 UTC
ThreadId 22 at 2019-12-13 13:39:00.003116 UTC
ThreadId 23 at 2019-12-13 13:40:00.00399 UTC
ThreadId 24 at 2019-12-13 13:41:00.00291 UTC
ThreadId 25 at 2019-12-13 13:42:00.001187 UTC
ThreadId 26 at 2019-12-13 13:43:00.002664 UTC

I sometimes need to wait around 10 minutes to get this error.

I experience this issue in a MacOs Mojave as another colleague of mine but others don't get it in a Linux based OS.

Did anybody experienced the same behavior or do you have any hint to help on this topic?

Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions