@@ -10,7 +10,15 @@ class Action
1010{
1111 public function emit ()
1212 {
13-
13+ if (! $ receiver = config ('scheduledaction.receiver ' )) return ;
14+
15+ if (! class_exists ($ receiver ) && ! is_callable (new $ receiver )) return ;
16+
17+ $ callableReceiver = new $ receiver ;
18+ call_user_func (
19+ $ callableReceiver ,
20+ $ this ->needsToRunToday ( config ('scheduledaction.actions_per_poll ' ) )
21+ );
1422 }
1523
1624 protected function getPendingSchedules ($ date = null , $ limit = 10 , $ orderBy = 'asc ' ) : Collection {
@@ -19,18 +27,20 @@ protected function getPendingSchedules($date = null, $limit = 10, $orderBy = 'as
1927 $ date = $ date ?? Carbon::now ();
2028 $ day = strtoupper ($ date ->englishDayOfWeek );
2129
22- return ModelAction::pending ()
23- ->where (function ($ query ) use ($ date ) {
30+ return ModelAction::query ()
31+ ->with ('actionable ' )
32+ ->pending ()
33+ ->where (function ($ query ) use ($ date , $ day ) {
2434 $ query
25- ->whereDate ('act_on ' , $ date );
26- })
27- -> when ( $ day , function ( $ query , $ day ) {
28- return $ query
29- -> orWhere ( function ( $ query ) use ($ day ) {
30- $ query ->whereHas ( ' recurringDays ' , function ( Builder $ query ) use ( $ day ) {
31- $ query -> where ( ' day ' , $ day );
35+ ->whereDate ('act_on ' , $ date )
36+ -> when ( $ day , function ( $ query , $ day ) {
37+ return $ query
38+ -> orWhere ( function ( $ query) use ( $ day ) {
39+ $ query -> whereHas ( ' recurringDays ' , function ( Builder $ query ) use ($ day ) {
40+ $ query ->where ( ' day ' , $ day );
41+ } );
3242 });
33- });
43+ });
3444 })
3545 ->orderByRaw ('TIME(`act_at`) ' . $ orderBy )
3646 ->take ($ limit )
0 commit comments