Skip to content

Commit

Permalink
Improve the Queue Service
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyCyborg committed Apr 30, 2018
1 parent ab68760 commit 5815f9d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Application extends Container implements ResponsePreparerInterface
*
* @var string
*/
const VERSION = '4.0.46';
const VERSION = '4.0.47';

/**
* Indicates if the application has "booted".
Expand Down
24 changes: 9 additions & 15 deletions src/Queue/Jobs/SyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SyncJob extends Job
*
* @var string
*/
protected $data;
protected $payload;


/**
* Create a new job instance.
Expand All @@ -33,10 +34,10 @@ class SyncJob extends Job
* @param string $data
* @return void
*/
public function __construct(Container $container, $job, $data = '')
public function __construct(Container $container, $payload, $queue = '')
{
$this->job = $job;
$this->data = $data;
$this->payload = $payload;
$this->queue = $queue;
$this->container = $container;
}

Expand All @@ -47,16 +48,9 @@ public function __construct(Container $container, $job, $data = '')
*/
public function handle()
{
$data = json_decode($this->data, true);

if ($this->job instanceof Closure) {
call_user_func($this->job, $this, $data);
} else {
$this->resolveAndHandle(array(
'job' => $this->job,
'data' => $data
));
}
$payload = json_decode($this->getRawBody(), true);

$this->resolveAndHandle($payload);
}

/**
Expand All @@ -66,7 +60,7 @@ public function handle()
*/
public function getRawBody()
{
//
return $this->payload;
}

/**
Expand Down
17 changes: 11 additions & 6 deletions src/Queue/Queues/SyncQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SyncQueue extends Queue implements QueueInterface
*/
public function push($job, $data = '', $queue = null)
{
$this->resolveJob($job, json_encode($data))->handle();
$queueJob = $this->resolveJob($this->createPayload($job, $data, $queue), $queue);

$queueJob->handle();

return 0;
}
Expand Down Expand Up @@ -58,18 +60,21 @@ public function later($delay, $job, $data = '', $queue = null)
* @param string $queue
* @return \Nova\Queue\Jobs\Job|null
*/
public function pop($queue = null) {}
public function pop($queue = null)
{
//
}

/**
* Resolve a Sync job instance.
*
* @param string $job
* @param string $data
* @param string $payload
* @param string $queues
* @return \Nova\Queue\Jobs\SyncJob
*/
protected function resolveJob($job, $data)
protected function resolveJob($payload, $queue)
{
return new SyncJob($this->container, $job, $data);
return new SyncJob($this->container, $payload, $queue);
}

}

0 comments on commit 5815f9d

Please sign in to comment.