@@ -66,28 +66,34 @@ public function __construct(IDBConnection $connection, IConfig $config, ITimeFac
6666	 * @param mixed $argument 
6767	 */ 
6868	public  function  add ($ job$ argumentnull ) {
69- 		if  (!$ this has ($ job$ argument
70- 			if  ($ jobinstanceof  IJob) {
71- 				$ classget_class ($ job
72- 			} else  {
73- 				$ class$ job
74- 			}
69+ 		if  ($ jobinstanceof  IJob) {
70+ 			$ classget_class ($ job
71+ 		} else  {
72+ 			$ class$ job
73+ 		}
7574
76- 			 $ argument json_encode ($ argument
77- 			 if  (strlen ($ argument 4000 ) {
78- 				 throw  new  \InvalidArgumentException ('Background job arguments can \'t exceed 4000 characters (json encoded) ' );
79- 			 }
75+ 		$ argumentJson json_encode ($ argument
76+ 		if  (strlen ($ argumentJson 4000 ) {
77+ 			throw  new  \InvalidArgumentException ('Background job arguments can \'t exceed 4000 characters (json encoded) ' );
78+ 		}
8079
81- 			$ query$ this connection ->getQueryBuilder ();
80+ 		$ query$ this connection ->getQueryBuilder ();
81+ 		if  (!$ this has ($ job$ argument
8282			$ queryinsert ('jobs ' )
8383				->values ([
8484					'class '  => $ querycreateNamedParameter ($ class
85- 					'argument '  => $ querycreateNamedParameter ($ argument 
85+ 					'argument '  => $ querycreateNamedParameter ($ argumentJson 
8686					'last_run '  => $ querycreateNamedParameter (0 , IQueryBuilder::PARAM_INT ),
8787					'last_checked '  => $ querycreateNamedParameter ($ this timeFactory ->getTime (), IQueryBuilder::PARAM_INT ),
8888				]);
89- 			$ queryexecute ();
89+ 		} else  {
90+ 			$ queryupdate ('jobs ' )
91+ 				->set ('reserved_at ' , $ queryexpr ()->literal (0 , IQueryBuilder::PARAM_INT ))
92+ 				->set ('last_checked ' , $ querycreateNamedParameter ($ this timeFactory ->getTime (), IQueryBuilder::PARAM_INT ))
93+ 				->where ($ queryexpr ()->eq ('class ' , $ querycreateNamedParameter ($ class
94+ 				->andWhere ($ queryexpr ()->eq ('argument ' , $ querycreateNamedParameter ($ argumentJson
9095		}
96+ 		$ queryexecute ();
9197	}
9298
9399	/** 
0 commit comments