def test_1_daemon_auto_start(self): # First stop the daemon if it's running. # print("test_1_daemon_auto_start: stop") # for debug akjobd.do_action("stop") psleep(2) self.assertFalse(os.path.isfile(pidfile)) # print("test_1_daemon_auto_start: auto-start off") # for debug # Environment variable so the daemon doesn't auto-start. os.putenv('AKJOB_START_DAEMON', "False") # Just running the management script should auto-start akjob. run([akjob_python, os.path.join(settings.BASE_DIR, "manage.py")], stdout=DEVNULL) # check that the daemon didn't auto-start. self.assertFalse(os.path.isfile(pidfile)) # print("test_1_daemon_auto_start: auto-start on") # for debug # Environment variable so the daemon does auto-start. os.putenv('AKJOB_START_DAEMON', "True") # Just running the management script should auto-start akjob. run([akjob_python, os.path.join(settings.BASE_DIR, "manage.py")], stdout=DEVNULL) psleep(2) # check that the daemon did auto-start. self.assertTrue(os.path.isfile(pidfile)) # set autostart to false to not confuse things with other tests. os.putenv('AKJOB_START_DAEMON', "False")
def test_4_daemon_run_once_only(self): akjobd.do_action("start") sleep(1) pid1 = akjobd.get_pid_from_pidfile() akjobd.do_action("start") sleep(1) pid2 = akjobd.get_pid_from_pidfile() self.assertEqual(pid1, pid2)
def test_2_start_stop_daemon(self): # print("test_2_start_stop_daemon: stop") # for debug akjobd.do_action("stop") psleep(2) self.assertFalse(os.path.isfile(pidfile)) # print("test_2_start_stop_daemon: start") # for debug start_daemon() psleep(2) self.assertTrue(os.path.isfile(pidfile)) # print("test_2_start_stop_daemon: stop") # for debug akjobd.do_action("stop") psleep(2) self.assertFalse(os.path.isfile(pidfile))
def tearDownModule(): # Make sure the unittest akjobd isn't running akjobd.do_action("stop") sleep(1) if os.path.isfile(pidfile): raise Exception("Unittest akjobd PID file still exists.") # delete the log files. delete test files. for logfilename in testfiles: try: os.remove(os.path.join(testdir, logfilename)) except FileNotFoundError: pass # remove the testdir os.rmdir(testdir)
def test_5_log_files_exist(self): akjobd.do_action("start") sleep(1) # there should be akjobd.log and akjobd.out but there may not be a # akjob.job.log since no jobs are scheduled. if (os.path.isfile(os.path.join(testdir, "akjobd.log")) is True and os.path.isfile(os.path.join(testdir, "akjobd.out")) is True): self.assertNotEqual( 0, os.path.getsize(os.path.join(testdir, "akjobd.out"))) self.assertNotEqual( 0, os.path.getsize(os.path.join(testdir, "akjobd.log"))) else: self.assertTrue(os.path.isfile(os.path.join(testdir, "akjobd.log"))) self.assertTrue(os.path.isfile(os.path.join(testdir, "akjobd.out")))
def test_1_daemon_auto_start(self): # First stop the daemon if it's running. akjobd.do_action("stop") sleep(1) self.assertFalse(os.path.isfile(pidfile)) # Environment variable so the daemon doesn't auto-start. os.putenv('AKJOB_START_DAEMON', "False") # Just running the management script should auto-start akjob. run(["python", os.path.join(settings.BASE_DIR, "manage.py")], stdout=DEVNULL) # check that the daemon didn't auto-start. self.assertFalse(os.path.isfile(pidfile)) # Environment variable so the daemon does auto-start. os.putenv('AKJOB_START_DAEMON', "True") # Just running the management script should auto-start akjob. run(["python", os.path.join(settings.BASE_DIR, "manage.py")], stdout=DEVNULL) sleep(1) # check that the daemon did auto-start. self.assertTrue(os.path.isfile(pidfile))
def handle(self, *args, **options): # akjobd configuration if options["piddir"] is not None: akjobd.piddir = options["piddir"] if options["pidname"] is not None: akjobd.pidfile = options["pidname"] if options["logdir"] is not None: akjobd.logdir = options["logdir"] akjobd.setup() # do the stuff if options["action"] == "start": akjobd.do_action("start") elif options["action"] == "stop": akjobd.do_action("stop") elif options["action"] == "restart": akjobd.do_action("restart") elif options["action"] == "reloadfixture": models.load_DayOfMonth(refresh=True) models.load_DayOfWeek(refresh=True) models.load_Months(refresh=True) elif options["action"] == "joblist": models.list_jobs() elif options["action"] in ["enablejob", "disablejob", "deletejob", "showinfo"]: if options["id"] is None: raise CommandError( 'Job id is required with action "' + options["action"] + '".') try: if not models.job_exists(int(options["id"])): raise CommandError("Job " + options["id"] + " doesn't exist.") except ValueError: raise CommandError("The id supplied is not an integer.") if options["action"] == "enablejob": models.enable_job(int(options["id"])) elif options["action"] == "disablejob": models.disable_job(int(options["id"])) elif options["action"] == "deletejob": models.delete_job(int(options["id"])) elif options["action"] == "showinfo": models.Job.objects.get(id=int(options["id"])).print()
def test_4_wait(self): akjobd.do_action("stop") psleep(60) start_daemon() # sleep so jobs have time to run. psleep(210)
def test_3_start_daemon(self): akjobd.do_action("stop") sleep(1) start_daemon() sleep(1) self.assertTrue(os.path.isfile(pidfile))
def test_2_stop_daemon(self): start_daemon() sleep(1) akjobd.do_action("stop") sleep(1) self.assertFalse(os.path.isfile(pidfile))