public static function boot() { parent::boot(); static::creating(function ($workerunit) { // dd($workerunit); // Inherit type, domain and format if (empty($workerunit->type) or empty($workerunit->domain) or empty($workerunit->format)) { $j = Job::where('_id', $workerunit->job_id)->first(); $workerunit->type = $j->type; $workerunit->domain = $j->domain; $workerunit->format = $j->format; } $workerunit->annotationVector = $workerunit->createAnnotationVector(); // Activity if not exists if (empty($workerunit->activity_id)) { try { $activity = new Activity(); $activity->label = "Workerunit is saved."; $activity->softwareAgent_id = $workerunit->softwareAgent_id; $activity->save(); $workerunit->activity_id = $activity->_id; Log::debug("Saving workerunit {$workerunit->_id} with activity {$workerunit->activity_id}."); } catch (Exception $e) { if ($activity) { $activity->forceDelete(); } //if($workerunit) $workerunit->forceDelete(); throw new Exception('Error saving activity for workerunit.'); } } }); }
public static function boot() { parent::boot(); static::creating(function ($jobconf) { // IFEXISTS CHECK IS NOT HERE. try { $c = $jobconf->content; if (isset($c['reward'])) { $c['reward'] = (double) $c['reward']; } if (isset($c['hitLifetimeInMinutes'])) { $c['hitLifetimeInMinutes'] = intval($c['hitLifetimeInMinutes']); } if (isset($c['autoApprovalDelayInMinutes'])) { $c['autoApprovalDelayInMinutes'] = intval($c['autoApprovalDelayInMinutes']); } if (isset($c['expirationInMinutes'])) { $c['expirationInMinutes'] = intval($c['expirationInMinutes']); } if (isset($c['workerunitsPerUnit'])) { $c['workerunitsPerUnit'] = intval($c['workerunitsPerUnit']); } if (isset($c['unitsPerTask'])) { $c['unitsPerTask'] = intval($c['unitsPerTask']); if ($c['unitsPerTask'] == 0) { $c['unitsPerTask'] = 1; } } $jobconf->content = $c; } catch (Exception $e) { if ($jobconf) { $jobconf->forceDelete(); } throw new Exception('Error saving JobConfiguration.'); } if (empty($jobconf->activity_id)) { try { $activity = new Activity(); $activity->label = "JobConfiguration is saved."; $activity->softwareAgent_id = 'jobcreator'; $activity->save(); $jobconf->activity_id = $activity->_id; Log::debug("Saved JobConfiguration with activity {$jobconf->activity_id}."); } catch (Exception $e) { if ($activity) { $activity->forceDelete(); } if ($jobconf) { $jobconf->forceDelete(); } throw new Exception('Error saving activity for JobConfiguration.'); } } }); }
public static function boot() { parent::boot(); static::saving(function ($job) { \Log::debug('Clearing jobCache and mainSearchFilters.'); \MongoDB\Temp::whereIn('_id', ['mainSearchFilters', 'jobCache', $job->_id])->forceDelete(); }); static::creating(function ($job) { try { if (!SoftwareAgent::find('jobcreator')) { $softwareAgent = new SoftwareAgent(); $softwareAgent->_id = 'jobcreator'; $softwareAgent->label = "Job creation"; } if (!isset($job->projectedCost) and !isset($job->iamemptyjob)) { $reward = $job->jobConfiguration->content['reward']; $workerunitsPerUnit = intval($job->jobConfiguration->content['workerunitsPerUnit']); $unitsPerTask = intval($job->jobConfiguration->content['unitsPerTask']); $unitsCount = count($job->batch->wasDerivedFrom); if (!$unitsPerTask) { $projectedCost = 0; } else { $projectedCost = round($reward / $unitsPerTask * ($unitsCount * $workerunitsPerUnit), 2); } $job->expectedWorkerunitsCount = $unitsCount * $job->jobConfiguration->content['workerunitsPerUnit']; $job->projectedCost = $projectedCost; } $job->unitsCount = count($job->batch->wasDerivedFrom); $job->latestMetrics = 0; $job->workerunitsCount = 0; $job->completion = 0.0; // 0.00-1.00 if (!isset($job->activity_id)) { $activity = new Activity(); $activity->label = "Job is uploaded to crowdsourcing platform."; $activity->softwareAgent_id = 'jobcreator'; // TODO: JOB softwareAgent_id = $platform. Does this need to be the same? $activity->save(); $job->activity_id = $activity->_id; } } catch (Exception $e) { // Something went wrong with creating the Entity $job->forceDelete(); throw $e; } Log::debug("Saved entity {$job->_id} with activity {$job->activity_id}."); }); }
public static function boot() { parent::boot(); static::saving(function ($questiontemplate) { if (empty($questiontemplate->activity_id)) { try { $activity = new Activity(); $activity->label = "Questiontemplate is saved."; $activity->softwareAgent_id = 'templatebuilder'; $activity->save(); $questiontemplate->activity_id = $activity->_id; Log::debug("Saving QuestionTemplate {$questiontemplate->_id} with activity {$questiontemplate->activity_id}."); } catch (Exception $e) { if ($activity) { $activity->forceDelete(); } if ($questiontemplate) { $questiontemplate->forceDelete(); } throw new Exception('Error saving activity for QuestionTemplate.'); } } }); }